home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources / reload1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-27  |  204.4 KB  |  6,168 lines  |  [TEXT/MPS ]

  1. /* Reload pseudo regs into hard regs for insns that require hard regs.
  2.    Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include "config.h"
  23. #include "rtl.h"
  24. #include "obstack.h"
  25. #include "insn-config.h"
  26. #include "insn-flags.h"
  27. #include "insn-codes.h"
  28. #include "flags.h"
  29. #include "expr.h"
  30. #include "regs.h"
  31. #include "hard-reg-set.h"
  32. #include "reload.h"
  33. #include "recog.h"
  34. #include "basic-block.h"
  35. #include "output.h"
  36.  
  37. #ifdef MPW
  38. extern int MPW_reload_again;
  39. #endif
  40.  
  41. /* This file contains the reload pass of the compiler, which is
  42.    run after register allocation has been done.  It checks that
  43.    each insn is valid (operands required to be in registers really
  44.    are in registers of the proper class) and fixes up invalid ones
  45.    by copying values temporarily into registers for the insns
  46.    that need them.
  47.  
  48.    The results of register allocation are described by the vector
  49.    reg_renumber; the insns still contain pseudo regs, but reg_renumber
  50.    can be used to find which hard reg, if any, a pseudo reg is in.
  51.  
  52.    The technique we always use is to free up a few hard regs that are
  53.    called ``reload regs'', and for each place where a pseudo reg
  54.    must be in a hard reg, copy it temporarily into one of the reload regs.
  55.  
  56.    All the pseudos that were formerly allocated to the hard regs that
  57.    are now in use as reload regs must be ``spilled''.  This means
  58.    that they go to other hard regs, or to stack slots if no other
  59.    available hard regs can be found.  Spilling can invalidate more
  60.    insns, requiring additional need for reloads, so we must keep checking
  61.    until the process stabilizes.
  62.  
  63.    For machines with different classes of registers, we must keep track
  64.    of the register class needed for each reload, and make sure that
  65.    we allocate enough reload registers of each class.
  66.  
  67.    The file reload.c contains the code that checks one insn for
  68.    validity and reports the reloads that it needs.  This file
  69.    is in charge of scanning the entire rtl code, accumulating the
  70.    reload needs, spilling, assigning reload registers to use for
  71.    fixing up each insn, and generating the new insns to copy values
  72.    into the reload registers.  */
  73.  
  74. /* During reload_as_needed, element N contains a REG rtx for the hard reg
  75.    into which pseudo reg N has been reloaded (perhaps for a previous insn). */
  76. static rtx *reg_last_reload_reg;
  77.  
  78. /* Elt N nonzero if reg_last_reload_reg[N] has been set in this insn
  79.    for an output reload that stores into reg N.  */
  80. static char *reg_has_output_reload;
  81.  
  82. /* Indicates which hard regs are reload-registers for an output reload
  83.    in the current insn.  */
  84. static HARD_REG_SET reg_is_output_reload;
  85.  
  86. /* Element N is the constant value to which pseudo reg N is equivalent,
  87.    or zero if pseudo reg N is not equivalent to a constant.
  88.    find_reloads looks at this in order to replace pseudo reg N
  89.    with the constant it stands for.  */
  90. rtx *reg_equiv_constant;
  91.  
  92. /* Element N is a memory location to which pseudo reg N is equivalent,
  93.    prior to any register elimination (such as frame pointer to stack
  94.    pointer).  Depending on whether or not it is a valid address, this value
  95.    is transferred to either reg_equiv_address or reg_equiv_mem.  */
  96. rtx *reg_equiv_memory_loc;
  97.  
  98. /* Element N is the address of stack slot to which pseudo reg N is equivalent.
  99.    This is used when the address is not valid as a memory address
  100.    (because its displacement is too big for the machine.)  */
  101. rtx *reg_equiv_address;
  102.  
  103. /* Element N is the memory slot to which pseudo reg N is equivalent,
  104.    or zero if pseudo reg N is not equivalent to a memory slot.  */
  105. rtx *reg_equiv_mem;
  106.  
  107. /* Widest width in which each pseudo reg is referred to (via subreg).  */
  108. static int *reg_max_ref_width;
  109.  
  110. /* Element N is the insn that initialized reg N from its equivalent
  111.    constant or memory slot.  */
  112. static rtx *reg_equiv_init;
  113.  
  114. /* During reload_as_needed, element N contains the last pseudo regno
  115.    reloaded into the Nth reload register.  This vector is in parallel
  116.    with spill_regs.  If that pseudo reg occupied more than one register,
  117.    reg_reloaded_contents points to that pseudo for each spill register in
  118.    use; all of these must remain set for an inheritance to occur.  */
  119. static int reg_reloaded_contents[FIRST_PSEUDO_REGISTER];
  120.  
  121. /* During reload_as_needed, element N contains the insn for which
  122.    the Nth reload register was last used.  This vector is in parallel
  123.    with spill_regs, and its contents are significant only when
  124.    reg_reloaded_contents is significant.  */
  125. static rtx reg_reloaded_insn[FIRST_PSEUDO_REGISTER];
  126.  
  127. /* Number of spill-regs so far; number of valid elements of spill_regs.  */
  128. static int n_spills;
  129.  
  130. /* In parallel with spill_regs, contains REG rtx's for those regs.
  131.    Holds the last rtx used for any given reg, or 0 if it has never
  132.    been used for spilling yet.  This rtx is reused, provided it has
  133.    the proper mode.  */
  134. static rtx spill_reg_rtx[FIRST_PSEUDO_REGISTER];
  135.  
  136. /* In parallel with spill_regs, contains nonzero for a spill reg
  137.    that was stored after the last time it was used.
  138.    The precise value is the insn generated to do the store.  */
  139. static rtx spill_reg_store[FIRST_PSEUDO_REGISTER];
  140.  
  141. /* This table is the inverse mapping of spill_regs:
  142.    indexed by hard reg number,
  143.    it contains the position of that reg in spill_regs,
  144.    or -1 for something that is not in spill_regs.  */
  145. static short spill_reg_order[FIRST_PSEUDO_REGISTER];
  146.  
  147. /* This reg set indicates registers that may not be used for retrying global
  148.    allocation.  The registers that may not be used include all spill registers
  149.    and the frame pointer (if we are using one).  */
  150. HARD_REG_SET forbidden_regs;
  151.  
  152. /* This reg set indicates registers that are not good for spill registers.
  153.    They will not be used to complete groups of spill registers.  This includes
  154.    all fixed registers, registers that may be eliminated, and registers
  155.    explicitly used in the rtl.
  156.  
  157.    (spill_reg_order prevents these registers from being used to start a
  158.    group.)  */
  159. static HARD_REG_SET bad_spill_regs;
  160.  
  161. /* Describes order of use of registers for reloading
  162.    of spilled pseudo-registers.  `spills' is the number of
  163.    elements that are actually valid; new ones are added at the end.  */
  164. static short spill_regs[FIRST_PSEUDO_REGISTER];
  165.  
  166. /* Describes order of preference for putting regs into spill_regs.
  167.    Contains the numbers of all the hard regs, in order most preferred first.
  168.    This order is different for each function.
  169.    It is set up by order_regs_for_reload.
  170.    Empty elements at the end contain -1.  */
  171. static short potential_reload_regs[FIRST_PSEUDO_REGISTER];
  172.  
  173. /* 1 for a hard register that appears explicitly in the rtl
  174.    (for example, function value registers, special registers
  175.    used by insns, structure value pointer registers).  */
  176. static char regs_explicitly_used[FIRST_PSEUDO_REGISTER];
  177.  
  178. /* Indicates if a register was counted against the need for
  179.    groups.  0 means it can count against max_nongroup instead.  */
  180. static HARD_REG_SET counted_for_groups;
  181.  
  182. /* Indicates if a register was counted against the need for
  183.    non-groups.  0 means it can become part of a new group.
  184.    During choose_reload_regs, 1 here means don't use this reg
  185.    as part of a group, even if it seems to be otherwise ok.  */
  186. static HARD_REG_SET counted_for_nongroups;
  187.  
  188. /* Nonzero if indirect addressing is supported on the machine; this means
  189.    that spilling (REG n) does not require reloading it into a register in
  190.    order to do (MEM (REG n)) or (MEM (PLUS (REG n) (CONST_INT c))).  The
  191.    value indicates the level of indirect addressing supported, e.g., two
  192.    means that (MEM (MEM (REG n))) is also valid if (REG n) does not get
  193.    a hard register.  */
  194.  
  195. static char spill_indirect_levels;
  196.  
  197. /* Nonzero if indirect addressing is supported when the innermost MEM is
  198.    of the form (MEM (SYMBOL_REF sym)).  It is assumed that the level to
  199.    which these are valid is the same as spill_indirect_levels, above.   */
  200.  
  201. char indirect_symref_ok;
  202.  
  203. /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid.  */
  204.  
  205. char double_reg_address_ok;
  206.  
  207. /* Record the stack slot for each spilled hard register.  */
  208.  
  209. static rtx spill_stack_slot[FIRST_PSEUDO_REGISTER];
  210.  
  211. /* Width allocated so far for that stack slot.  */
  212.  
  213. static int spill_stack_slot_width[FIRST_PSEUDO_REGISTER];
  214.  
  215. /* Indexed by register class and basic block number, nonzero if there is
  216.    any need for a spill register of that class in that basic block.
  217.    The pointer is 0 if we did stupid allocation and don't know
  218.    the structure of basic blocks.  */
  219.  
  220. char *basic_block_needs[N_REG_CLASSES];
  221.  
  222. /* First uid used by insns created by reload in this function.
  223.    Used in find_equiv_reg.  */
  224. int reload_first_uid;
  225.  
  226. /* Flag set by local-alloc or global-alloc if anything is live in
  227.    a call-clobbered reg across calls.  */
  228.  
  229. int caller_save_needed;
  230.  
  231. /* Set to 1 while reload_as_needed is operating.
  232.    Required by some machines to handle any generated moves differently.  */
  233.  
  234. int reload_in_progress = 0;
  235.  
  236. /* These arrays record the insn_code of insns that may be needed to
  237.    perform input and output reloads of special objects.  They provide a
  238.    place to pass a scratch register.  */
  239.  
  240. enum insn_code reload_in_optab[NUM_MACHINE_MODES];
  241. enum insn_code reload_out_optab[NUM_MACHINE_MODES];
  242.  
  243. /* This obstack is used for allocation of rtl during register elimination.
  244.    The allocated storage can be freed once find_reloads has processed the
  245.    insn.  */
  246.  
  247. struct obstack reload_obstack;
  248. char *reload_firstobj;
  249.  
  250. #define obstack_chunk_alloc xmalloc
  251. #define obstack_chunk_free free
  252.  
  253. /* List of labels that must never be deleted.  */
  254. extern rtx forced_labels;
  255.  
  256. /* This structure is used to record information about register eliminations.
  257.    Each array entry describes one possible way of eliminating a register
  258.    in favor of another.   If there is more than one way of eliminating a
  259.    particular register, the most preferred should be specified first.  */
  260.  
  261. static struct elim_table
  262. {
  263.   int from;            /* Register number to be eliminated. */
  264.   int to;            /* Register number used as replacement. */
  265.   int initial_offset;        /* Initial difference between values. */
  266.   int can_eliminate;        /* Non-zero if this elimination can be done. */
  267.   int can_eliminate_previous;    /* Value of CAN_ELIMINATE in previous scan over
  268.                    insns made by reload. */
  269.   int offset;            /* Current offset between the two regs. */
  270.   int max_offset;        /* Maximum offset between the two regs. */
  271.   int previous_offset;        /* Offset at end of previous insn. */
  272.   int ref_outside_mem;        /* "to" has been referenced outside a MEM. */
  273.   rtx from_rtx;            /* REG rtx for the register to be eliminated.
  274.                    We cannot simply compare the number since
  275.                    we might then spuriously replace a hard
  276.                    register corresponding to a pseudo
  277.                    assigned to the reg to be eliminated. */
  278.   rtx to_rtx;            /* REG rtx for the replacement. */
  279. } reg_eliminate[] =
  280.  
  281. /* If a set of eliminable registers was specified, define the table from it.
  282.    Otherwise, default to the normal case of the frame pointer being
  283.    replaced by the stack pointer.  */
  284.  
  285. #ifdef ELIMINABLE_REGS
  286.   ELIMINABLE_REGS;
  287. #else
  288.   {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}};
  289. #endif
  290.  
  291. #define NUM_ELIMINABLE_REGS (sizeof reg_eliminate / sizeof reg_eliminate[0])
  292.  
  293. /* Record the number of pending eliminations that have an offset not equal
  294.    to their initial offset.  If non-zero, we use a new copy of each
  295.    replacement result in any insns encountered.  */
  296. static int num_not_at_initial_offset;
  297.  
  298. /* Count the number of registers that we may be able to eliminate.  */
  299. static int num_eliminable;
  300.  
  301. /* For each label, we record the offset of each elimination.  If we reach
  302.    a label by more than one path and an offset differs, we cannot do the
  303.    elimination.  This information is indexed by the number of the label.
  304.    The first table is an array of flags that records whether we have yet
  305.    encountered a label and the second table is an array of arrays, one
  306.    entry in the latter array for each elimination.  */
  307.  
  308. static char *offsets_known_at;
  309. static int (*offsets_at)[NUM_ELIMINABLE_REGS];
  310.  
  311. /* Number of labels in the current function.  */
  312.  
  313. static int num_labels;
  314.  
  315. void mark_home_live ();
  316. static void count_possible_groups ();
  317. static int possible_group_p ();
  318. static void scan_paradoxical_subregs ();
  319. static void reload_as_needed ();
  320. static int modes_equiv_for_class_p ();
  321. static void alter_reg ();
  322. static void delete_dead_insn ();
  323. static void spill_failure ();
  324. static int new_spill_reg();
  325. static void set_label_offsets ();
  326. static int eliminate_regs_in_insn ();
  327. static void mark_not_eliminable ();
  328. static int spill_hard_reg ();
  329. static void choose_reload_regs ();
  330. static void emit_reload_insns ();
  331. static void delete_output_reload ();
  332. static void forget_old_reloads_1 ();
  333. static void order_regs_for_reload ();
  334. static rtx inc_for_reload ();
  335. static int constraint_accepts_reg_p ();
  336. static int count_occurrences ();
  337.  
  338. extern void remove_death ();
  339. extern rtx adj_offsettable_operand ();
  340. extern rtx form_sum ();
  341.  
  342. void
  343. init_reload ()
  344. {
  345.   register int i;
  346.  
  347.   /* Often (MEM (REG n)) is still valid even if (REG n) is put on the stack.
  348.      Set spill_indirect_levels to the number of levels such addressing is
  349.      permitted, zero if it is not permitted at all.  */
  350.  
  351.   register rtx tem
  352.     = gen_rtx (MEM, DPmode,
  353.            gen_rtx (PLUS, DPmode,
  354.             gen_rtx (REG, DPmode, LAST_VIRTUAL_REGISTER + 1),
  355.             GEN_INT (4)));
  356.   spill_indirect_levels = 0;
  357.  
  358.   while (memory_address_p (QImode, tem))
  359.     {
  360.       spill_indirect_levels++;
  361.       tem = gen_rtx (MEM, DPmode, tem);
  362.     }
  363.  
  364.   /* See if indirect addressing is valid for (MEM (SYMBOL_REF ...)).  */
  365.  
  366.   tem = gen_rtx (MEM, DPmode, gen_rtx (SYMBOL_REF, DPmode, "foo"));
  367.   indirect_symref_ok = memory_address_p (QImode, tem);
  368.  
  369.   /* See if reg+reg is a valid (and offsettable) address.  */
  370.  
  371.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  372.     {
  373.       tem = gen_rtx (PLUS, DPmode,
  374.              gen_rtx (REG, DPmode, FRAME_POINTER_REGNUM),
  375.              gen_rtx (REG, DPmode, i));
  376.       /* This way, we make sure that reg+reg is an offsettable address.  */
  377.       tem = plus_constant (tem, 4);
  378.  
  379.       if (memory_address_p (QImode, tem))
  380.     {
  381.       double_reg_address_ok = 1;
  382.       break;
  383.     }
  384.     }
  385.  
  386.   /* Initialize obstack for our rtl allocation. */
  387.   gcc_obstack_init (&reload_obstack);
  388.   reload_firstobj = (char *) obstack_alloc (&reload_obstack, 0);
  389.  
  390. #ifdef HAVE_SECONDARY_RELOADS
  391.  
  392.   /* Initialize the optabs for doing special input and output reloads.  */
  393.  
  394.   for (i = 0; i < NUM_MACHINE_MODES; i++)
  395.     reload_in_optab[i] = reload_out_optab[i] = CODE_FOR_nothing;
  396.  
  397. #ifdef HAVE_reload_inqi
  398.   if (HAVE_reload_inqi)
  399.     reload_in_optab[(int) QImode] = CODE_FOR_reload_inqi;
  400. #endif
  401. #ifdef HAVE_reload_inhi
  402.   if (HAVE_reload_inhi)
  403.     reload_in_optab[(int) HImode] = CODE_FOR_reload_inhi;
  404. #endif
  405. #ifdef HAVE_reload_insi
  406.   if (HAVE_reload_insi)
  407.     reload_in_optab[(int) SImode] = CODE_FOR_reload_insi;
  408. #endif
  409. #ifdef HAVE_reload_indi
  410.   if (HAVE_reload_indi)
  411.     reload_in_optab[(int) DImode] = CODE_FOR_reload_indi;
  412. #endif
  413. #ifdef HAVE_reload_inti
  414.   if (HAVE_reload_inti)
  415.     reload_in_optab[(int) TImode] = CODE_FOR_reload_inti;
  416. #endif
  417. #ifdef HAVE_reload_insf
  418.   if (HAVE_reload_insf)
  419.     reload_in_optab[(int) SFmode] = CODE_FOR_reload_insf;
  420. #endif
  421. #ifdef HAVE_reload_indf
  422.   if (HAVE_reload_indf)
  423.     reload_in_optab[(int) DFmode] = CODE_FOR_reload_indf;
  424. #endif
  425. #ifdef HAVE_reload_inxf
  426.   if (HAVE_reload_inxf)
  427.     reload_in_optab[(int) XFmode] = CODE_FOR_reload_inxf;
  428. #endif
  429. #ifdef HAVE_reload_intf
  430.   if (HAVE_reload_intf)
  431.     reload_in_optab[(int) TFmode] = CODE_FOR_reload_intf;
  432. #endif
  433.  
  434. #ifdef HAVE_reload_outqi
  435.   if (HAVE_reload_outqi)
  436.     reload_out_optab[(int) QImode] = CODE_FOR_reload_outqi;
  437. #endif
  438. #ifdef HAVE_reload_outhi
  439.   if (HAVE_reload_outhi)
  440.     reload_out_optab[(int) HImode] = CODE_FOR_reload_outhi;
  441. #endif
  442. #ifdef HAVE_reload_outsi
  443.   if (HAVE_reload_outsi)
  444.     reload_out_optab[(int) SImode] = CODE_FOR_reload_outsi;
  445. #endif
  446. #ifdef HAVE_reload_outdi
  447.   if (HAVE_reload_outdi)
  448.     reload_out_optab[(int) DImode] = CODE_FOR_reload_outdi;
  449. #endif
  450. #ifdef HAVE_reload_outti
  451.   if (HAVE_reload_outti)
  452.     reload_out_optab[(int) TImode] = CODE_FOR_reload_outti;
  453. #endif
  454. #ifdef HAVE_reload_outsf
  455.   if (HAVE_reload_outsf)
  456.     reload_out_optab[(int) SFmode] = CODE_FOR_reload_outsf;
  457. #endif
  458. #ifdef HAVE_reload_outdf
  459.   if (HAVE_reload_outdf)
  460.     reload_out_optab[(int) DFmode] = CODE_FOR_reload_outdf;
  461. #endif
  462. #ifdef HAVE_reload_outxf
  463.   if (HAVE_reload_outxf)
  464.     reload_out_optab[(int) XFmode] = CODE_FOR_reload_outxf;
  465. #endif
  466. #ifdef HAVE_reload_outtf
  467.   if (HAVE_reload_outtf)
  468.     reload_out_optab[(int) TFmode] = CODE_FOR_reload_outtf;
  469. #endif
  470.  
  471. #endif /* HAVE_SECONDARY_RELOADS */
  472.  
  473. }
  474.  
  475. /* Main entry point for the reload pass, and only entry point
  476.    in this file.
  477.  
  478.    FIRST is the first insn of the function being compiled.
  479.  
  480.    GLOBAL nonzero means we were called from global_alloc
  481.    and should attempt to reallocate any pseudoregs that we
  482.    displace from hard regs we will use for reloads.
  483.    If GLOBAL is zero, we do not have enough information to do that,
  484.    so any pseudo reg that is spilled must go to the stack.
  485.  
  486.    DUMPFILE is the global-reg debugging dump file stream, or 0.
  487.    If it is nonzero, messages are written to it to describe
  488.    which registers are seized as reload regs, which pseudo regs
  489.    are spilled from them, and where the pseudo regs are reallocated to.
  490.  
  491.    Return value is nonzero if reload failed
  492.    and we must not do any more for this function.  */
  493.  
  494. int
  495. reload (first, global, dumpfile)
  496.      rtx first;
  497.      int global;
  498.      FILE *dumpfile;
  499. {
  500.   register int class;
  501.   register int i;
  502.   register rtx insn;
  503.   register struct elim_table *ep;
  504.  
  505.   int something_changed;
  506.   int something_needs_reloads;
  507.   int something_needs_elimination;
  508.   int new_basic_block_needs;
  509.   enum reg_class caller_save_spill_class = NO_REGS;
  510.   int caller_save_group_size = 1;
  511.  
  512.   /* Nonzero means we couldn't get enough spill regs.  */
  513.   int failure = 0;
  514.  
  515.   /* The basic block number currently being processed for INSN.  */
  516.   int this_block;
  517.  
  518.   /* Make sure even insns with volatile mem refs are recognizable.  */
  519.   init_recog ();
  520.  
  521.   /* Enable find_equiv_reg to distinguish insns made by reload.  */
  522.   reload_first_uid = get_max_uid ();
  523.  
  524.   for (i = 0; i < N_REG_CLASSES; i++)
  525.     basic_block_needs[i] = 0;
  526.  
  527. #ifdef SECONDARY_MEMORY_NEEDED
  528.   /* Initialize the secondary memory table.  */
  529.   clear_secondary_mem ();
  530. #endif
  531.  
  532.   /* Remember which hard regs appear explicitly
  533.      before we merge into `regs_ever_live' the ones in which
  534.      pseudo regs have been allocated.  */
  535.   bcopy (regs_ever_live, regs_explicitly_used, sizeof regs_ever_live);
  536.  
  537.   /* We don't have a stack slot for any spill reg yet.  */
  538.   bzero (spill_stack_slot, sizeof spill_stack_slot);
  539.   bzero (spill_stack_slot_width, sizeof spill_stack_slot_width);
  540.  
  541.   /* Initialize the save area information for caller-save, in case some
  542.      are needed.  */
  543.   init_save_areas ();
  544.  
  545.   /* Compute which hard registers are now in use
  546.      as homes for pseudo registers.
  547.      This is done here rather than (eg) in global_alloc
  548.      because this point is reached even if not optimizing.  */
  549.  
  550.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  551.     mark_home_live (i);
  552.  
  553.   /* Make sure that the last insn in the chain
  554.      is not something that needs reloading.  */
  555.   emit_note (NULL_PTR, NOTE_INSN_DELETED);
  556.  
  557.   /* Find all the pseudo registers that didn't get hard regs
  558.      but do have known equivalent constants or memory slots.
  559.      These include parameters (known equivalent to parameter slots)
  560.      and cse'd or loop-moved constant memory addresses.
  561.  
  562.      Record constant equivalents in reg_equiv_constant
  563.      so they will be substituted by find_reloads.
  564.      Record memory equivalents in reg_mem_equiv so they can
  565.      be substituted eventually by altering the REG-rtx's.  */
  566.  
  567.   reg_equiv_constant = (rtx *) alloca (max_regno * sizeof (rtx));
  568.   bzero (reg_equiv_constant, max_regno * sizeof (rtx));
  569.   reg_equiv_memory_loc = (rtx *) alloca (max_regno * sizeof (rtx));
  570.   bzero (reg_equiv_memory_loc, max_regno * sizeof (rtx));
  571.   reg_equiv_mem = (rtx *) alloca (max_regno * sizeof (rtx));
  572.   bzero (reg_equiv_mem, max_regno * sizeof (rtx));
  573.   reg_equiv_init = (rtx *) alloca (max_regno * sizeof (rtx));
  574.   bzero (reg_equiv_init, max_regno * sizeof (rtx));
  575.   reg_equiv_address = (rtx *) alloca (max_regno * sizeof (rtx));
  576.   bzero (reg_equiv_address, max_regno * sizeof (rtx));
  577.   reg_max_ref_width = (int *) alloca (max_regno * sizeof (int));
  578.   bzero (reg_max_ref_width, max_regno * sizeof (int));
  579.  
  580.   /* Look for REG_EQUIV notes; record what each pseudo is equivalent to.
  581.      Also find all paradoxical subregs
  582.      and find largest such for each pseudo.  */
  583.  
  584.   for (insn = first; insn; insn = NEXT_INSN (insn))
  585.     {
  586.       rtx set = single_set (insn);
  587.  
  588.       if (set != 0 && GET_CODE (SET_DEST (set)) == REG)
  589.     {
  590.       rtx note = find_reg_note (insn, REG_EQUIV, NULL_RTX);
  591.       if (note
  592. #ifdef LEGITIMATE_PIC_OPERAND_P
  593.           && (! CONSTANT_P (XEXP (note, 0)) || ! flag_pic
  594.           || LEGITIMATE_PIC_OPERAND_P (XEXP (note, 0)))
  595. #endif
  596.           )
  597.         {
  598.           rtx x = XEXP (note, 0);
  599.           i = REGNO (SET_DEST (set));
  600.           if (i > LAST_VIRTUAL_REGISTER)
  601.         {
  602.           if (GET_CODE (x) == MEM)
  603.             reg_equiv_memory_loc[i] = x;
  604.           else if (CONSTANT_P (x))
  605.             {
  606.               if (LEGITIMATE_CONSTANT_P (x))
  607.             reg_equiv_constant[i] = x;
  608.               else
  609.             reg_equiv_memory_loc[i]
  610.               = force_const_mem (GET_MODE (SET_DEST (set)), x);
  611.             }
  612.           else
  613.             continue;
  614.  
  615.           /* If this register is being made equivalent to a MEM
  616.              and the MEM is not SET_SRC, the equivalencing insn
  617.              is one with the MEM as a SET_DEST and it occurs later.
  618.              So don't mark this insn now.  */
  619.           if (GET_CODE (x) != MEM
  620.               || rtx_equal_p (SET_SRC (set), x))
  621.             reg_equiv_init[i] = insn;
  622.         }
  623.         }
  624.     }
  625.  
  626.       /* If this insn is setting a MEM from a register equivalent to it,
  627.      this is the equivalencing insn.  */
  628.       else if (set && GET_CODE (SET_DEST (set)) == MEM
  629.            && GET_CODE (SET_SRC (set)) == REG
  630.            && reg_equiv_memory_loc[REGNO (SET_SRC (set))]
  631.            && rtx_equal_p (SET_DEST (set),
  632.                    reg_equiv_memory_loc[REGNO (SET_SRC (set))]))
  633.     reg_equiv_init[REGNO (SET_SRC (set))] = insn;
  634.  
  635.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  636.     scan_paradoxical_subregs (PATTERN (insn));
  637.     }
  638.  
  639.   /* Does this function require a frame pointer?  */
  640.  
  641.   frame_pointer_needed = (! flag_omit_frame_pointer
  642. #ifdef EXIT_IGNORE_STACK
  643.               /* ?? If EXIT_IGNORE_STACK is set, we will not save
  644.                  and restore sp for alloca.  So we can't eliminate
  645.                  the frame pointer in that case.  At some point,
  646.                  we should improve this by emitting the
  647.                  sp-adjusting insns for this case.  */
  648.               || (current_function_calls_alloca
  649.                   && EXIT_IGNORE_STACK)
  650. #endif
  651.               || FRAME_POINTER_REQUIRED);
  652.  
  653.   num_eliminable = 0;
  654.  
  655.   /* Initialize the table of registers to eliminate.  The way we do this
  656.      depends on how the eliminable registers were defined.  */
  657. #ifdef ELIMINABLE_REGS
  658.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  659.     {
  660.       ep->can_eliminate = ep->can_eliminate_previous
  661.     = (CAN_ELIMINATE (ep->from, ep->to)
  662.        && (ep->from != FRAME_POINTER_REGNUM || ! frame_pointer_needed));
  663.     }
  664. #else
  665.   reg_eliminate[0].can_eliminate = reg_eliminate[0].can_eliminate_previous
  666.     = ! frame_pointer_needed;
  667. #endif
  668.  
  669.   /* Count the number of eliminable registers and build the FROM and TO
  670.      REG rtx's.  Note that code in gen_rtx will cause, e.g.,
  671.      gen_rtx (REG, Pmode, STACK_POINTER_REGNUM) to equal stack_pointer_rtx.
  672.      We depend on this.  */
  673.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  674.     {
  675.       num_eliminable += ep->can_eliminate;
  676.       ep->from_rtx = gen_rtx (REG, DPmode, ep->from);
  677.       ep->to_rtx = gen_rtx (REG, DPmode, ep->to);
  678.     }
  679.  
  680.   num_labels = max_label_num () - get_first_label_num ();
  681.  
  682.   /* Allocate the tables used to store offset information at labels.  */
  683.   offsets_known_at = (char *) alloca (num_labels);
  684.   offsets_at
  685.     = (int (*)[NUM_ELIMINABLE_REGS])
  686.       alloca (num_labels * NUM_ELIMINABLE_REGS * sizeof (int));
  687.  
  688.   offsets_known_at -= get_first_label_num ();
  689.   offsets_at -= get_first_label_num ();
  690.  
  691.   /* Alter each pseudo-reg rtx to contain its hard reg number.
  692.      Assign stack slots to the pseudos that lack hard regs or equivalents.
  693.      Do not touch virtual registers.  */
  694.  
  695.   for (i = LAST_VIRTUAL_REGISTER + 1; i < max_regno; i++)
  696.     alter_reg (i, -1);
  697.  
  698.   /* Round size of stack frame to BIGGEST_ALIGNMENT.  This must be done here
  699.      because the stack size may be a part of the offset computation for
  700.      register elimination.   */
  701.   assign_stack_local (BLKmode, 0, 0);
  702.  
  703.   /* If we have some registers we think can be eliminated, scan all insns to
  704.      see if there is an insn that sets one of these registers to something
  705.      other than itself plus a constant.  If so, the register cannot be
  706.      eliminated.  Doing this scan here eliminates an extra pass through the
  707.      main reload loop in the most common case where register elimination
  708.      cannot be done.  */
  709.   for (insn = first; insn && num_eliminable; insn = NEXT_INSN (insn))
  710.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  711.     || GET_CODE (insn) == CALL_INSN)
  712.       note_stores (PATTERN (insn), mark_not_eliminable);
  713.  
  714. #ifndef REGISTER_CONSTRAINTS
  715.   /* If all the pseudo regs have hard regs,
  716.      except for those that are never referenced,
  717.      we know that no reloads are needed.  */
  718.   /* But that is not true if there are register constraints, since
  719.      in that case some pseudos might be in the wrong kind of hard reg.  */
  720.  
  721.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  722.     if (reg_renumber[i] == -1 && reg_n_refs[i] != 0)
  723.       break;
  724.  
  725.   if (i == max_regno && num_eliminable == 0 && ! caller_save_needed)
  726.     return;
  727. #endif
  728.  
  729.   /* Compute the order of preference for hard registers to spill.
  730.      Store them by decreasing preference in potential_reload_regs.  */
  731.  
  732.   order_regs_for_reload ();
  733.  
  734.   /* So far, no hard regs have been spilled.  */
  735.   n_spills = 0;
  736.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  737.     spill_reg_order[i] = -1;
  738.  
  739.   /* On most machines, we can't use any register explicitly used in the
  740.      rtl as a spill register.  But on some, we have to.  Those will have
  741.      taken care to keep the life of hard regs as short as possible.  */
  742.  
  743. #ifdef SMALL_REGISTER_CLASSES
  744.   CLEAR_HARD_REG_SET (forbidden_regs);
  745. #else
  746.   COPY_HARD_REG_SET (forbidden_regs, bad_spill_regs);
  747. #endif
  748.  
  749.   /* Spill any hard regs that we know we can't eliminate.  */
  750.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  751.     if (! ep->can_eliminate)
  752.       {
  753.     spill_hard_reg (ep->from, global, dumpfile, 1);
  754.     regs_ever_live[ep->from] = 1;
  755.       }
  756.  
  757.   if (global)
  758.     for (i = 0; i < N_REG_CLASSES; i++)
  759.       {
  760.     basic_block_needs[i] = (char *)alloca (n_basic_blocks);
  761.     bzero (basic_block_needs[i], n_basic_blocks);
  762.       }
  763.  
  764.   /* From now on, we need to emit any moves without making new pseudos.  */
  765.   reload_in_progress = 1;
  766.  
  767.   /* This loop scans the entire function each go-round
  768.      and repeats until one repetition spills no additional hard regs.  */
  769.  
  770.   /* This flag is set when a pseudo reg is spilled,
  771.      to require another pass.  Note that getting an additional reload
  772.      reg does not necessarily imply any pseudo reg was spilled;
  773.      sometimes we find a reload reg that no pseudo reg was allocated in.  */
  774.   something_changed = 1;
  775.   /* This flag is set if there are any insns that require reloading.  */
  776.   something_needs_reloads = 0;
  777.   /* This flag is set if there are any insns that require register
  778.      eliminations.  */
  779.   something_needs_elimination = 0;
  780.   while (something_changed)
  781.     {
  782.       rtx after_call = 0;
  783.  
  784.       /* For each class, number of reload regs needed in that class.
  785.      This is the maximum over all insns of the needs in that class
  786.      of the individual insn.  */
  787.       int max_needs[N_REG_CLASSES];
  788.       /* For each class, size of group of consecutive regs
  789.      that is needed for the reloads of this class.  */
  790.       int group_size[N_REG_CLASSES];
  791.       /* For each class, max number of consecutive groups needed.
  792.      (Each group contains group_size[CLASS] consecutive registers.)  */
  793.       int max_groups[N_REG_CLASSES];
  794.       /* For each class, max number needed of regs that don't belong
  795.      to any of the groups.  */
  796.       int max_nongroups[N_REG_CLASSES];
  797.       /* For each class, the machine mode which requires consecutive
  798.      groups of regs of that class.
  799.      If two different modes ever require groups of one class,
  800.      they must be the same size and equally restrictive for that class,
  801.      otherwise we can't handle the complexity.  */
  802.       enum machine_mode group_mode[N_REG_CLASSES];
  803.       /* Record the insn where each maximum need is first found.  */
  804.       rtx max_needs_insn[N_REG_CLASSES];
  805.       rtx max_groups_insn[N_REG_CLASSES];
  806.       rtx max_nongroups_insn[N_REG_CLASSES];
  807.       rtx x;
  808.       int starting_frame_size = get_frame_size ();
  809.       static char *reg_class_names[] = REG_CLASS_NAMES;
  810.  
  811.       something_changed = 0;
  812.       bzero (max_needs, sizeof max_needs);
  813.       bzero (max_groups, sizeof max_groups);
  814.       bzero (max_nongroups, sizeof max_nongroups);
  815.       bzero (max_needs_insn, sizeof max_needs_insn);
  816.       bzero (max_groups_insn, sizeof max_groups_insn);
  817.       bzero (max_nongroups_insn, sizeof max_nongroups_insn);
  818.       bzero (group_size, sizeof group_size);
  819.       for (i = 0; i < N_REG_CLASSES; i++)
  820.     group_mode[i] = VOIDmode;
  821.  
  822.       /* Keep track of which basic blocks are needing the reloads.  */
  823.       this_block = 0;
  824.  
  825.       /* Remember whether any element of basic_block_needs
  826.      changes from 0 to 1 in this pass.  */
  827.       new_basic_block_needs = 0;
  828.  
  829.       /* Reset all offsets on eliminable registers to their initial values.  */
  830. #ifdef ELIMINABLE_REGS
  831.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  832.     {
  833.       INITIAL_ELIMINATION_OFFSET (ep->from, ep->to, ep->initial_offset);
  834.       ep->previous_offset = ep->offset
  835.         = ep->max_offset = ep->initial_offset;
  836.     }
  837. #else
  838. #ifdef INITIAL_FRAME_POINTER_OFFSET
  839.       INITIAL_FRAME_POINTER_OFFSET (reg_eliminate[0].initial_offset);
  840. #else
  841.       if (!FRAME_POINTER_REQUIRED)
  842.     abort ();
  843.       reg_eliminate[0].initial_offset = 0;
  844. #endif
  845.       reg_eliminate[0].previous_offset = reg_eliminate[0].max_offset
  846.     = reg_eliminate[0].offset = reg_eliminate[0].initial_offset;
  847. #endif
  848.  
  849.       num_not_at_initial_offset = 0;
  850.  
  851.       bzero (&offsets_known_at[get_first_label_num ()], num_labels);
  852.  
  853.       /* Set a known offset for each forced label to be at the initial offset
  854.      of each elimination.  We do this because we assume that all
  855.      computed jumps occur from a location where each elimination is
  856.      at its initial offset.  */
  857.  
  858.       for (x = forced_labels; x; x = XEXP (x, 1))
  859.     if (XEXP (x, 0))
  860.       set_label_offsets (XEXP (x, 0), NULL_RTX, 1);
  861.  
  862.       /* For each pseudo register that has an equivalent location defined,
  863.      try to eliminate any eliminable registers (such as the frame pointer)
  864.      assuming initial offsets for the replacement register, which
  865.      is the normal case.
  866.  
  867.      If the resulting location is directly addressable, substitute
  868.      the MEM we just got directly for the old REG.
  869.  
  870.      If it is not addressable but is a constant or the sum of a hard reg
  871.      and constant, it is probably not addressable because the constant is
  872.      out of range, in that case record the address; we will generate
  873.      hairy code to compute the address in a register each time it is
  874.      needed.
  875.  
  876.      If the location is not addressable, but does not have one of the
  877.      above forms, assign a stack slot.  We have to do this to avoid the
  878.      potential of producing lots of reloads if, e.g., a location involves
  879.      a pseudo that didn't get a hard register and has an equivalent memory
  880.      location that also involves a pseudo that didn't get a hard register.
  881.  
  882.      Perhaps at some point we will improve reload_when_needed handling
  883.      so this problem goes away.  But that's very hairy.  */
  884.  
  885.       for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  886.     if (reg_renumber[i] < 0 && reg_equiv_memory_loc[i])
  887.       {
  888.         rtx x = eliminate_regs (reg_equiv_memory_loc[i], 0, NULL_RTX);
  889.  
  890.         if (strict_memory_address_p (GET_MODE (regno_reg_rtx[i]),
  891.                      XEXP (x, 0)))
  892.           reg_equiv_mem[i] = x, reg_equiv_address[i] = 0;
  893.         else if (CONSTANT_P (XEXP (x, 0))
  894.              || (GET_CODE (XEXP (x, 0)) == PLUS
  895.              && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
  896.              && (REGNO (XEXP (XEXP (x, 0), 0))
  897.                  < FIRST_PSEUDO_REGISTER)
  898.              && CONSTANT_P (XEXP (XEXP (x, 0), 1))))
  899.           reg_equiv_address[i] = XEXP (x, 0), reg_equiv_mem[i] = 0;
  900.         else
  901.           {
  902.         /* Make a new stack slot.  Then indicate that something
  903.            changed so we go back and recompute offsets for
  904.            eliminable registers because the allocation of memory
  905.            below might change some offset.  reg_equiv_{mem,address}
  906.            will be set up for this pseudo on the next pass around
  907.            the loop.  */
  908.         reg_equiv_memory_loc[i] = 0;
  909.         reg_equiv_init[i] = 0;
  910.         alter_reg (i, -1);
  911.         something_changed = 1;
  912.           }
  913.       }
  914.  
  915.       /* If we allocated another pseudo to the stack, redo elimination
  916.      bookkeeping.  */
  917.       if (something_changed)
  918.     continue;
  919.  
  920.       /* If caller-saves needs a group, initialize the group to include
  921.      the size and mode required for caller-saves.  */
  922.  
  923.       if (caller_save_group_size > 1)
  924.     {
  925.       group_mode[(int) caller_save_spill_class] = DPmode;
  926.       group_size[(int) caller_save_spill_class] = caller_save_group_size;
  927.     }
  928.  
  929.       /* Compute the most additional registers needed by any instruction.
  930.      Collect information separately for each class of regs.  */
  931.  
  932.       for (insn = first; insn; insn = NEXT_INSN (insn))
  933.     {
  934.       if (global && this_block + 1 < n_basic_blocks
  935.           && insn == basic_block_head[this_block+1])
  936.         ++this_block;
  937.  
  938.       /* If this is a label, a JUMP_INSN, or has REG_NOTES (which
  939.          might include REG_LABEL), we need to see what effects this
  940.          has on the known offsets at labels.  */
  941.  
  942.       if (GET_CODE (insn) == CODE_LABEL || GET_CODE (insn) == JUMP_INSN
  943.           || (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  944.           && REG_NOTES (insn) != 0))
  945.         set_label_offsets (insn, insn, 0);
  946.  
  947.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  948.         {
  949.           /* Nonzero means don't use a reload reg that overlaps
  950.          the place where a function value can be returned.  */
  951.           rtx avoid_return_reg = 0;
  952.  
  953.           rtx old_body = PATTERN (insn);
  954.           int old_code = INSN_CODE (insn);
  955.            rtx old_notes = REG_NOTES (insn);
  956.           int did_elimination = 0;
  957.  
  958.           /* Initially, count RELOAD_OTHER reloads.
  959.          Later, merge in the other kinds.  */
  960.           int insn_needs[N_REG_CLASSES];
  961.           int insn_groups[N_REG_CLASSES];
  962.           int insn_total_groups = 0;
  963.  
  964.           /* Count RELOAD_FOR_INPUT_RELOAD_ADDRESS reloads.  */
  965.           int insn_needs_for_inputs[N_REG_CLASSES];
  966.           int insn_groups_for_inputs[N_REG_CLASSES];
  967.           int insn_total_groups_for_inputs = 0;
  968.  
  969.           /* Count RELOAD_FOR_OUTPUT_RELOAD_ADDRESS reloads.  */
  970.           int insn_needs_for_outputs[N_REG_CLASSES];
  971.           int insn_groups_for_outputs[N_REG_CLASSES];
  972.           int insn_total_groups_for_outputs = 0;
  973.  
  974.           /* Count RELOAD_FOR_OPERAND_ADDRESS reloads.  */
  975.           int insn_needs_for_operands[N_REG_CLASSES];
  976.           int insn_groups_for_operands[N_REG_CLASSES];
  977.           int insn_total_groups_for_operands = 0;
  978.  
  979. #if 0  /* This wouldn't work nowadays, since optimize_bit_field
  980.       looks for non-strict memory addresses.  */
  981.           /* Optimization: a bit-field instruction whose field
  982.          happens to be a byte or halfword in memory
  983.          can be changed to a move instruction.  */
  984.  
  985.           if (GET_CODE (PATTERN (insn)) == SET)
  986.         {
  987.           rtx dest = SET_DEST (PATTERN (insn));
  988.           rtx src = SET_SRC (PATTERN (insn));
  989.  
  990.           if (GET_CODE (dest) == ZERO_EXTRACT
  991.               || GET_CODE (dest) == SIGN_EXTRACT)
  992.             optimize_bit_field (PATTERN (insn), insn, reg_equiv_mem);
  993.           if (GET_CODE (src) == ZERO_EXTRACT
  994.               || GET_CODE (src) == SIGN_EXTRACT)
  995.             optimize_bit_field (PATTERN (insn), insn, reg_equiv_mem);
  996.         }
  997. #endif
  998.  
  999.           /* If needed, eliminate any eliminable registers.  */
  1000.           if (num_eliminable)
  1001.         did_elimination = eliminate_regs_in_insn (insn, 0);
  1002.  
  1003. #ifdef SMALL_REGISTER_CLASSES
  1004.           /* Set avoid_return_reg if this is an insn
  1005.          that might use the value of a function call.  */
  1006.           if (GET_CODE (insn) == CALL_INSN)
  1007.         {
  1008.           if (GET_CODE (PATTERN (insn)) == SET)
  1009.             after_call = SET_DEST (PATTERN (insn));
  1010.           else if (GET_CODE (PATTERN (insn)) == PARALLEL
  1011.                && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  1012.             after_call = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
  1013.           else
  1014.             after_call = 0;
  1015.         }
  1016.           else if (after_call != 0
  1017.                && !(GET_CODE (PATTERN (insn)) == SET
  1018.                 && SET_DEST (PATTERN (insn)) == stack_pointer_rtx))
  1019.         {
  1020.           if (reg_mentioned_p (after_call, PATTERN (insn)))
  1021.             avoid_return_reg = after_call;
  1022.           after_call = 0;
  1023.         }
  1024. #endif /* SMALL_REGISTER_CLASSES */
  1025.  
  1026.           /* Analyze the instruction.  */
  1027.           find_reloads (insn, 0, spill_indirect_levels, global,
  1028.                 spill_reg_order);
  1029.  
  1030.           /* Remember for later shortcuts which insns had any reloads or
  1031.          register eliminations.
  1032.  
  1033.          One might think that it would be worthwhile to mark insns
  1034.          that need register replacements but not reloads, but this is
  1035.          not safe because find_reloads may do some manipulation of
  1036.          the insn (such as swapping commutative operands), which would
  1037.          be lost when we restore the old pattern after register
  1038.          replacement.  So the actions of find_reloads must be redone in
  1039.          subsequent passes or in reload_as_needed.
  1040.  
  1041.          However, it is safe to mark insns that need reloads
  1042.          but not register replacement.  */
  1043.  
  1044.           PUT_MODE (insn, (did_elimination ? QImode
  1045.                    : n_reloads ? HImode
  1046.                    : VOIDmode));
  1047.  
  1048.           /* Discard any register replacements done.  */
  1049.           if (did_elimination)
  1050.         {
  1051.           obstack_free (&reload_obstack, reload_firstobj);
  1052.           PATTERN (insn) = old_body;
  1053.           INSN_CODE (insn) = old_code;
  1054.            REG_NOTES (insn) = old_notes;
  1055.           something_needs_elimination = 1;
  1056.         }
  1057.  
  1058.           /* If this insn has no reloads, we need not do anything except
  1059.          in the case of a CALL_INSN when we have caller-saves and
  1060.          caller-save needs reloads.  */
  1061.  
  1062.           if (n_reloads == 0
  1063.           && ! (GET_CODE (insn) == CALL_INSN
  1064.             && caller_save_spill_class != NO_REGS))
  1065.         continue;
  1066.  
  1067.           something_needs_reloads = 1;
  1068.  
  1069.           for (i = 0; i < N_REG_CLASSES; i++)
  1070.         {
  1071.           insn_needs[i] = 0, insn_groups[i] = 0;
  1072.           insn_needs_for_inputs[i] = 0, insn_groups_for_inputs[i] = 0;
  1073.           insn_needs_for_outputs[i] = 0, insn_groups_for_outputs[i] = 0;
  1074.           insn_needs_for_operands[i] = 0, insn_groups_for_operands[i] = 0;
  1075.         }
  1076.  
  1077.           /* Count each reload once in every class
  1078.          containing the reload's own class.  */
  1079.  
  1080.           for (i = 0; i < n_reloads; i++)
  1081.         {
  1082.           register enum reg_class *p;
  1083.           enum reg_class class = reload_reg_class[i];
  1084.           int size;
  1085.           enum machine_mode mode;
  1086.           int *this_groups;
  1087.           int *this_needs;
  1088.           int *this_total_groups;
  1089.  
  1090.           /* Don't count the dummy reloads, for which one of the
  1091.              regs mentioned in the insn can be used for reloading.
  1092.              Don't count optional reloads.
  1093.              Don't count reloads that got combined with others.  */
  1094.           if (reload_reg_rtx[i] != 0
  1095.               || reload_optional[i] != 0
  1096.               || (reload_out[i] == 0 && reload_in[i] == 0
  1097.               && ! reload_secondary_p[i]))
  1098.               continue;
  1099.  
  1100.           /* Show that a reload register of this class is needed
  1101.              in this basic block.  We do not use insn_needs and
  1102.              insn_groups because they are overly conservative for
  1103.              this purpose.  */
  1104.           if (global && ! basic_block_needs[(int) class][this_block])
  1105.             {
  1106.               basic_block_needs[(int) class][this_block] = 1;
  1107.               new_basic_block_needs = 1;
  1108.             }
  1109.  
  1110.           /* Decide which time-of-use to count this reload for.  */
  1111.           switch (reload_when_needed[i])
  1112.             {
  1113.             case RELOAD_OTHER:
  1114.             case RELOAD_FOR_OUTPUT:
  1115.             case RELOAD_FOR_INPUT:
  1116.               this_needs = insn_needs;
  1117.               this_groups = insn_groups;
  1118.               this_total_groups = &insn_total_groups;
  1119.               break;
  1120.  
  1121.             case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1122.               this_needs = insn_needs_for_inputs;
  1123.               this_groups = insn_groups_for_inputs;
  1124.               this_total_groups = &insn_total_groups_for_inputs;
  1125.               break;
  1126.  
  1127.             case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  1128.               this_needs = insn_needs_for_outputs;
  1129.               this_groups = insn_groups_for_outputs;
  1130.               this_total_groups = &insn_total_groups_for_outputs;
  1131.               break;
  1132.  
  1133.             case RELOAD_FOR_OPERAND_ADDRESS:
  1134.               this_needs = insn_needs_for_operands;
  1135.               this_groups = insn_groups_for_operands;
  1136.               this_total_groups = &insn_total_groups_for_operands;
  1137.               break;
  1138.             }
  1139.  
  1140.           mode = reload_inmode[i];
  1141.           if (GET_MODE_SIZE (reload_outmode[i]) > GET_MODE_SIZE (mode))
  1142.             mode = reload_outmode[i];
  1143.           size = CLASS_MAX_NREGS (class, mode);
  1144.           if (size > 1)
  1145.             {
  1146.               enum machine_mode other_mode, allocate_mode;
  1147.  
  1148.               /* Count number of groups needed separately from
  1149.              number of individual regs needed.  */
  1150.               this_groups[(int) class]++;
  1151.               p = reg_class_superclasses[(int) class];
  1152.               while (*p != LIM_REG_CLASSES)
  1153.             this_groups[(int) *p++]++;
  1154.               (*this_total_groups)++;
  1155.  
  1156.               /* Record size and mode of a group of this class.  */
  1157.               /* If more than one size group is needed,
  1158.              make all groups the largest needed size.  */
  1159.               if (group_size[(int) class] < size)
  1160.             {
  1161.               other_mode = group_mode[(int) class];
  1162.               allocate_mode = mode;
  1163.  
  1164.               group_size[(int) class] = size;
  1165.               group_mode[(int) class] = mode;
  1166.             }
  1167.               else
  1168.             {
  1169.               other_mode = mode;
  1170.               allocate_mode = group_mode[(int) class];
  1171.             }
  1172.  
  1173.               /* Crash if two dissimilar machine modes both need
  1174.              groups of consecutive regs of the same class.  */
  1175.  
  1176.               if (other_mode != VOIDmode
  1177.               && other_mode != allocate_mode
  1178.               && ! modes_equiv_for_class_p (allocate_mode,
  1179.                             other_mode,
  1180.                             class))
  1181.             abort ();
  1182.             }
  1183.           else if (size == 1)
  1184.             {
  1185.               this_needs[(int) class] += 1;
  1186.               p = reg_class_superclasses[(int) class];
  1187.               while (*p != LIM_REG_CLASSES)
  1188.             this_needs[(int) *p++] += 1;
  1189.             }
  1190.           else
  1191.             abort ();
  1192.         }
  1193.  
  1194.           /* All reloads have been counted for this insn;
  1195.          now merge the various times of use.
  1196.          This sets insn_needs, etc., to the maximum total number
  1197.          of registers needed at any point in this insn.  */
  1198.  
  1199.           for (i = 0; i < N_REG_CLASSES; i++)
  1200.         {
  1201.           int this_max;
  1202.           this_max = insn_needs_for_inputs[i];
  1203.           if (insn_needs_for_outputs[i] > this_max)
  1204.             this_max = insn_needs_for_outputs[i];
  1205.           if (insn_needs_for_operands[i] > this_max)
  1206.             this_max = insn_needs_for_operands[i];
  1207.           insn_needs[i] += this_max;
  1208.           this_max = insn_groups_for_inputs[i];
  1209.           if (insn_groups_for_outputs[i] > this_max)
  1210.             this_max = insn_groups_for_outputs[i];
  1211.           if (insn_groups_for_operands[i] > this_max)
  1212.             this_max = insn_groups_for_operands[i];
  1213.           insn_groups[i] += this_max;
  1214.         }
  1215.  
  1216.           insn_total_groups += MAX (insn_total_groups_for_inputs,
  1217.                     MAX (insn_total_groups_for_outputs,
  1218.                          insn_total_groups_for_operands));
  1219.  
  1220.           /* If this is a CALL_INSN and caller-saves will need
  1221.          a spill register, act as if the spill register is
  1222.          needed for this insn.   However, the spill register
  1223.          can be used by any reload of this insn, so we only
  1224.          need do something if no need for that class has
  1225.          been recorded.
  1226.  
  1227.          The assumption that every CALL_INSN will trigger a
  1228.          caller-save is highly conservative, however, the number
  1229.          of cases where caller-saves will need a spill register but
  1230.          a block containing a CALL_INSN won't need a spill register
  1231.          of that class should be quite rare.
  1232.  
  1233.          If a group is needed, the size and mode of the group will
  1234.          have been set up at the beginning of this loop.  */
  1235.  
  1236.           if (GET_CODE (insn) == CALL_INSN
  1237.           && caller_save_spill_class != NO_REGS)
  1238.         {
  1239.           int *caller_save_needs
  1240.             = (caller_save_group_size > 1 ? insn_groups : insn_needs);
  1241.  
  1242.           if (caller_save_needs[(int) caller_save_spill_class] == 0)
  1243.             {
  1244.               register enum reg_class *p
  1245.             = reg_class_superclasses[(int) caller_save_spill_class];
  1246.  
  1247.               caller_save_needs[(int) caller_save_spill_class]++;
  1248.  
  1249.               while (*p != LIM_REG_CLASSES)
  1250.             caller_save_needs[(int) *p++] += 1;
  1251.             }
  1252.  
  1253.           if (caller_save_group_size > 1)
  1254.             insn_total_groups = MAX (insn_total_groups, 1);
  1255.  
  1256.  
  1257.                 /* Show that this basic block will need a register of
  1258.                    this class.  */
  1259.  
  1260.                 if (global
  1261.                     && ! (basic_block_needs[(int) caller_save_spill_class]
  1262.                           [this_block]))
  1263.                   {
  1264.                     basic_block_needs[(int) caller_save_spill_class]
  1265.                       [this_block] = 1;
  1266.                     new_basic_block_needs = 1;
  1267.                   }
  1268.         }
  1269.  
  1270. #ifdef SMALL_REGISTER_CLASSES
  1271.           /* If this insn stores the value of a function call,
  1272.          and that value is in a register that has been spilled,
  1273.          and if the insn needs a reload in a class
  1274.          that might use that register as the reload register,
  1275.          then add add an extra need in that class.
  1276.          This makes sure we have a register available that does
  1277.          not overlap the return value.  */
  1278.           if (avoid_return_reg)
  1279.         {
  1280.           int regno = REGNO (avoid_return_reg);
  1281.           int nregs
  1282.             = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  1283.           int r;
  1284.           int inc_groups = 0;
  1285.           for (r = regno; r < regno + nregs; r++)
  1286.             if (spill_reg_order[r] >= 0)
  1287.               for (i = 0; i < N_REG_CLASSES; i++)
  1288.             if (TEST_HARD_REG_BIT (reg_class_contents[i], r))
  1289.               {
  1290.                 if (insn_needs[i] > 0)
  1291.                   insn_needs[i]++;
  1292.                 if (insn_groups[i] > 0
  1293.                 && nregs > 1)
  1294.                   inc_groups = 1;
  1295.               }
  1296.           if (inc_groups)
  1297.             insn_groups[i]++;
  1298.         }
  1299. #endif /* SMALL_REGISTER_CLASSES */
  1300.  
  1301.           /* For each class, collect maximum need of any insn.  */
  1302.  
  1303.           for (i = 0; i < N_REG_CLASSES; i++)
  1304.         {
  1305.           if (max_needs[i] < insn_needs[i])
  1306.             {
  1307.               max_needs[i] = insn_needs[i];
  1308.               max_needs_insn[i] = insn;
  1309.             }
  1310.           if (max_groups[i] < insn_groups[i])
  1311.             {
  1312.               max_groups[i] = insn_groups[i];
  1313.               max_groups_insn[i] = insn;
  1314.             }
  1315.           if (insn_total_groups > 0)
  1316.             if (max_nongroups[i] < insn_needs[i])
  1317.               {
  1318.             max_nongroups[i] = insn_needs[i];
  1319.             max_nongroups_insn[i] = insn;
  1320.               }
  1321.         }
  1322.         }
  1323.       /* Note that there is a continue statement above.  */
  1324.     }
  1325.  
  1326.       /* If we allocated any new memory locations, make another pass
  1327.      since it might have changed elimination offsets.  */
  1328.       if (starting_frame_size != get_frame_size ())
  1329.     something_changed = 1;
  1330.  
  1331.       if (dumpfile)
  1332.     for (i = 0; i < N_REG_CLASSES; i++)
  1333.       {
  1334.         if (max_needs[i] > 0)
  1335.           fprintf (dumpfile,
  1336.              ";; Need %d reg%s of class %s (for insn %d).\n",
  1337.                max_needs[i], max_needs[i] == 1 ? "" : "s",
  1338.                reg_class_names[i], INSN_UID (max_needs_insn[i]));
  1339.         if (max_nongroups[i] > 0)
  1340.           fprintf (dumpfile,
  1341.                ";; Need %d nongroup reg%s of class %s (for insn %d).\n",
  1342.                max_nongroups[i], max_nongroups[i] == 1 ? "" : "s",
  1343.                reg_class_names[i], INSN_UID (max_nongroups_insn[i]));
  1344.         if (max_groups[i] > 0)
  1345.           fprintf (dumpfile,
  1346.                ";; Need %d group%s (%smode) of class %s (for insn %d).\n",
  1347.                max_groups[i], max_groups[i] == 1 ? "" : "s",
  1348.                mode_name[(int) group_mode[i]],
  1349.                reg_class_names[i], INSN_UID (max_groups_insn[i]));
  1350.       }
  1351.              
  1352.       /* If we have caller-saves, set up the save areas and see if caller-save
  1353.      will need a spill register.  */
  1354.  
  1355.       if (caller_save_needed
  1356.       && ! setup_save_areas (&something_changed)
  1357.       && caller_save_spill_class  == NO_REGS)
  1358.     {
  1359.       /* The class we will need depends on whether the machine
  1360.          supports the sum of two registers for an address; see
  1361.          find_address_reloads for details.  */
  1362.  
  1363.       caller_save_spill_class
  1364.         = double_reg_address_ok ? INDEX_REG_CLASS : BASE_REG_CLASS;
  1365.       caller_save_group_size
  1366.         = CLASS_MAX_NREGS (caller_save_spill_class, DPmode);
  1367.       something_changed = 1;
  1368.     }
  1369.  
  1370.       /* Now deduct from the needs for the registers already
  1371.      available (already spilled).  */
  1372.  
  1373.       CLEAR_HARD_REG_SET (counted_for_groups);
  1374.       CLEAR_HARD_REG_SET (counted_for_nongroups);
  1375.  
  1376.       /* First find all regs alone in their class
  1377.      and count them (if desired) for non-groups.
  1378.      We would be screwed if a group took the only reg in a class
  1379.      for which a non-group reload is needed.
  1380.      (Note there is still a bug; if a class has 2 regs,
  1381.      both could be stolen by groups and we would lose the same way.
  1382.      With luck, no machine will need a nongroup in a 2-reg class.)  */
  1383.  
  1384.       for (i = 0; i < n_spills; i++)
  1385.     {
  1386.       register enum reg_class *p;
  1387.       class = (int) REGNO_REG_CLASS (spill_regs[i]);
  1388.  
  1389.       if (reg_class_size[class] == 1 && max_nongroups[class] > 0)
  1390.         {
  1391.           max_needs[class]--;
  1392.           p = reg_class_superclasses[class];
  1393.           while (*p != LIM_REG_CLASSES)
  1394.         max_needs[(int) *p++]--;
  1395.  
  1396.           SET_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]);
  1397.           max_nongroups[class]--;
  1398.           p = reg_class_superclasses[class];
  1399.           while (*p != LIM_REG_CLASSES)
  1400.         {
  1401.           if (max_nongroups[(int) *p] > 0)
  1402.             SET_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]);
  1403.           max_nongroups[(int) *p++]--;
  1404.         }
  1405.         }
  1406.     }
  1407.  
  1408.       /* Now find all consecutive groups of spilled registers
  1409.      and mark each group off against the need for such groups.
  1410.      But don't count them against ordinary need, yet.  */
  1411.  
  1412.       count_possible_groups (group_size, group_mode, max_groups);
  1413.  
  1414.       /* Now count all spill regs against the individual need,
  1415.      This includes those counted above for groups,
  1416.      but not those previously counted for nongroups.
  1417.  
  1418.      Those that weren't counted_for_groups can also count against
  1419.      the not-in-group need.  */
  1420.  
  1421.       for (i = 0; i < n_spills; i++)
  1422.     {
  1423.       register enum reg_class *p;
  1424.       class = (int) REGNO_REG_CLASS (spill_regs[i]);
  1425.  
  1426.       /* Those counted at the beginning shouldn't be counted twice.  */
  1427.       if (! TEST_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]))
  1428.         {
  1429.           max_needs[class]--;
  1430.           p = reg_class_superclasses[class];
  1431.           while (*p != LIM_REG_CLASSES)
  1432.         max_needs[(int) *p++]--;
  1433.  
  1434.           if (! TEST_HARD_REG_BIT (counted_for_groups, spill_regs[i]))
  1435.         {
  1436.           if (max_nongroups[class] > 0)
  1437.             SET_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]);
  1438.           max_nongroups[class]--;
  1439.           p = reg_class_superclasses[class];
  1440.           while (*p != LIM_REG_CLASSES)
  1441.             {
  1442.               if (max_nongroups[(int) *p] > 0)
  1443.             SET_HARD_REG_BIT (counted_for_nongroups,
  1444.                       spill_regs[i]);
  1445.               max_nongroups[(int) *p++]--;
  1446.             }
  1447.         }
  1448.         }
  1449.     }
  1450.  
  1451.       /* See if anything that happened changes which eliminations are valid.
  1452.      For example, on the Sparc, whether or not the frame pointer can
  1453.      be eliminated can depend on what registers have been used.  We need
  1454.      not check some conditions again (such as flag_omit_frame_pointer)
  1455.      since they can't have changed.  */
  1456.  
  1457.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1458.     if ((ep->from == FRAME_POINTER_REGNUM && FRAME_POINTER_REQUIRED)
  1459. #ifdef ELIMINABLE_REGS
  1460.         || ! CAN_ELIMINATE (ep->from, ep->to)
  1461. #endif
  1462.         )
  1463.       ep->can_eliminate = 0;
  1464.  
  1465.       /* Look for the case where we have discovered that we can't replace
  1466.      register A with register B and that means that we will now be
  1467.      trying to replace register A with register C.  This means we can
  1468.      no longer replace register C with register B and we need to disable
  1469.      such an elimination, if it exists.  This occurs often with A == ap,
  1470.      B == sp, and C == fp.  */
  1471.  
  1472.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1473.     {
  1474.       struct elim_table *op;
  1475.       register int new_to = -1;
  1476.  
  1477.       if (! ep->can_eliminate && ep->can_eliminate_previous)
  1478.         {
  1479.           /* Find the current elimination for ep->from, if there is a
  1480.          new one.  */
  1481.           for (op = reg_eliminate;
  1482.            op < ®_eliminate[NUM_ELIMINABLE_REGS]; op++)
  1483.         if (op->from == ep->from && op->can_eliminate)
  1484.           {
  1485.             new_to = op->to;
  1486.             break;
  1487.           }
  1488.  
  1489.           /* See if there is an elimination of NEW_TO -> EP->TO.  If so,
  1490.          disable it.  */
  1491.           for (op = reg_eliminate;
  1492.            op < ®_eliminate[NUM_ELIMINABLE_REGS]; op++)
  1493.         if (op->from == new_to && op->to == ep->to)
  1494.           op->can_eliminate = 0;
  1495.         }
  1496.     }
  1497.  
  1498.       /* See if any registers that we thought we could eliminate the previous
  1499.      time are no longer eliminable.  If so, something has changed and we
  1500.      must spill the register.  Also, recompute the number of eliminable
  1501.      registers and see if the frame pointer is needed; it is if there is
  1502.      no elimination of the frame pointer that we can perform.  */
  1503.  
  1504.       frame_pointer_needed = 1;
  1505.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1506.     {
  1507.       if (ep->can_eliminate && ep->from == FRAME_POINTER_REGNUM)
  1508.         frame_pointer_needed = 0;
  1509.  
  1510.       if (! ep->can_eliminate && ep->can_eliminate_previous)
  1511.         {
  1512.           ep->can_eliminate_previous = 0;
  1513.           spill_hard_reg (ep->from, global, dumpfile, 1);
  1514.           regs_ever_live[ep->from] = 1;
  1515.           something_changed = 1;
  1516.           num_eliminable--;
  1517.         }
  1518.     }
  1519.  
  1520.       /* If all needs are met, we win.  */
  1521.  
  1522.       for (i = 0; i < N_REG_CLASSES; i++)
  1523.     if (max_needs[i] > 0 || max_groups[i] > 0 || max_nongroups[i] > 0)
  1524.       break;
  1525.       if (i == N_REG_CLASSES && !new_basic_block_needs && ! something_changed)
  1526.     break;
  1527.  
  1528.       /* Not all needs are met; must spill more hard regs.  */
  1529.  
  1530.       /* If any element of basic_block_needs changed from 0 to 1,
  1531.      re-spill all the regs already spilled.  This may spill
  1532.      additional pseudos that didn't spill before.  */
  1533.  
  1534.       if (new_basic_block_needs)
  1535.     for (i = 0; i < n_spills; i++)
  1536.       something_changed
  1537.         |= spill_hard_reg (spill_regs[i], global, dumpfile, 0);
  1538.  
  1539.       /* Now find more reload regs to satisfy the remaining need
  1540.      Do it by ascending class number, since otherwise a reg
  1541.      might be spilled for a big class and might fail to count
  1542.      for a smaller class even though it belongs to that class.
  1543.  
  1544.      Count spilled regs in `spills', and add entries to
  1545.      `spill_regs' and `spill_reg_order'.
  1546.  
  1547.      ??? Note there is a problem here.
  1548.      When there is a need for a group in a high-numbered class,
  1549.      and also need for non-group regs that come from a lower class,
  1550.      the non-group regs are chosen first.  If there aren't many regs,
  1551.      they might leave no room for a group.
  1552.  
  1553.      This was happening on the 386.  To fix it, we added the code
  1554.      that calls possible_group_p, so that the lower class won't
  1555.      break up the last possible group.
  1556.  
  1557.      Really fixing the problem would require changes above
  1558.      in counting the regs already spilled, and in choose_reload_regs.
  1559.      It might be hard to avoid introducing bugs there.  */
  1560.  
  1561.       for (class = 0; class < N_REG_CLASSES; class++)
  1562.     {
  1563.       /* First get the groups of registers.
  1564.          If we got single registers first, we might fragment
  1565.          possible groups.  */
  1566.       while (max_groups[class] > 0)
  1567.         {
  1568.           /* If any single spilled regs happen to form groups,
  1569.          count them now.  Maybe we don't really need
  1570.          to spill another group.  */
  1571.           count_possible_groups (group_size, group_mode, max_groups);
  1572.  
  1573.           /* Groups of size 2 (the only groups used on most machines)
  1574.          are treated specially.  */
  1575.           if (group_size[class] == 2)
  1576.         {
  1577.           /* First, look for a register that will complete a group.  */
  1578.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1579.             {
  1580.               int j = potential_reload_regs[i];
  1581.               int other;
  1582.               if (j >= 0 && ! TEST_HARD_REG_BIT (bad_spill_regs, j)
  1583.               &&
  1584.               ((j > 0 && (other = j - 1, spill_reg_order[other] >= 0)
  1585.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1586.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  1587.                 && HARD_REGNO_MODE_OK (other, group_mode[class])
  1588.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1589.                             other)
  1590.                 /* We don't want one part of another group.
  1591.                    We could get "two groups" that overlap!  */
  1592.                 && ! TEST_HARD_REG_BIT (counted_for_groups, other))
  1593.                ||
  1594.                (j < FIRST_PSEUDO_REGISTER - 1
  1595.                 && (other = j + 1, spill_reg_order[other] >= 0)
  1596.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1597.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  1598.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  1599.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1600.                             other)
  1601.                 && ! TEST_HARD_REG_BIT (counted_for_groups,
  1602.                             other))))
  1603.             {
  1604.               register enum reg_class *p;
  1605.  
  1606.               /* We have found one that will complete a group,
  1607.                  so count off one group as provided.  */
  1608.               max_groups[class]--;
  1609.               p = reg_class_superclasses[class];
  1610.               while (*p != LIM_REG_CLASSES)
  1611.                 max_groups[(int) *p++]--;
  1612.  
  1613.               /* Indicate both these regs are part of a group.  */
  1614.               SET_HARD_REG_BIT (counted_for_groups, j);
  1615.               SET_HARD_REG_BIT (counted_for_groups, other);
  1616.               break;
  1617.             }
  1618.             }
  1619.           /* We can't complete a group, so start one.  */
  1620.           if (i == FIRST_PSEUDO_REGISTER)
  1621.             for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1622.               {
  1623.             int j = potential_reload_regs[i];
  1624.             if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  1625.                 && spill_reg_order[j] < 0 && spill_reg_order[j + 1] < 0
  1626.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1627.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j + 1)
  1628.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  1629.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1630.                             j + 1))
  1631.               break;
  1632.               }
  1633.  
  1634.           /* I should be the index in potential_reload_regs
  1635.              of the new reload reg we have found.  */
  1636.  
  1637.           if (i >= FIRST_PSEUDO_REGISTER)
  1638.             {
  1639.               /* There are no groups left to spill.  */
  1640.               spill_failure (max_groups_insn[class]);
  1641.               failure = 1;
  1642.               goto failed;
  1643.             }
  1644.           else
  1645.             something_changed
  1646.               |= new_spill_reg (i, class, max_needs, NULL_PTR,
  1647.                     global, dumpfile);
  1648.         }
  1649.           else
  1650.         {
  1651.           /* For groups of more than 2 registers,
  1652.              look for a sufficient sequence of unspilled registers,
  1653.              and spill them all at once.  */
  1654.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1655.             {
  1656.               int j = potential_reload_regs[i];
  1657.               int k;
  1658.               if (j >= 0
  1659.               && j + group_size[class] <= FIRST_PSEUDO_REGISTER
  1660.               && HARD_REGNO_MODE_OK (j, group_mode[class]))
  1661.             {
  1662.               /* Check each reg in the sequence.  */
  1663.               for (k = 0; k < group_size[class]; k++)
  1664.                 if (! (spill_reg_order[j + k] < 0
  1665.                    && ! TEST_HARD_REG_BIT (bad_spill_regs, j + k)
  1666.                    && TEST_HARD_REG_BIT (reg_class_contents[class], j + k)))
  1667.                   break;
  1668.               /* We got a full sequence, so spill them all.  */
  1669.               if (k == group_size[class])
  1670.                 {
  1671.                   register enum reg_class *p;
  1672.                   for (k = 0; k < group_size[class]; k++)
  1673.                 {
  1674.                   int idx;
  1675.                   SET_HARD_REG_BIT (counted_for_groups, j + k);
  1676.                   for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++)
  1677.                     if (potential_reload_regs[idx] == j + k)
  1678.                       break;
  1679.                   something_changed
  1680.                     |= new_spill_reg (idx, class,
  1681.                               max_needs, NULL_PTR,
  1682.                               global, dumpfile);
  1683.                 }
  1684.  
  1685.                   /* We have found one that will complete a group,
  1686.                  so count off one group as provided.  */
  1687.                   max_groups[class]--;
  1688.                   p = reg_class_superclasses[class];
  1689.                   while (*p != LIM_REG_CLASSES)
  1690.                 max_groups[(int) *p++]--;
  1691.  
  1692.                   break;
  1693.                 }
  1694.             }
  1695.             }
  1696.           /* We couldn't find any registers for this reload.
  1697.              Avoid going into an infinite loop.  */
  1698.           if (i >= FIRST_PSEUDO_REGISTER)
  1699.             {
  1700.               /* There are no groups left.  */
  1701.               spill_failure (max_groups_insn[class]);
  1702.               failure = 1;
  1703.               goto failed;
  1704.             }
  1705.         }
  1706.         }
  1707.  
  1708.       /* Now similarly satisfy all need for single registers.  */
  1709.  
  1710.       while (max_needs[class] > 0 || max_nongroups[class] > 0)
  1711.         {
  1712.           /* Consider the potential reload regs that aren't
  1713.          yet in use as reload regs, in order of preference.
  1714.          Find the most preferred one that's in this class.  */
  1715.  
  1716.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1717.         if (potential_reload_regs[i] >= 0
  1718.             && TEST_HARD_REG_BIT (reg_class_contents[class],
  1719.                       potential_reload_regs[i])
  1720.             /* If this reg will not be available for groups,
  1721.                pick one that does not foreclose possible groups.
  1722.                This is a kludge, and not very general,
  1723.                but it should be sufficient to make the 386 work,
  1724.                and the problem should not occur on machines with
  1725.                more registers.  */
  1726.             && (max_nongroups[class] == 0
  1727.             || possible_group_p (potential_reload_regs[i], max_groups)))
  1728.           break;
  1729.  
  1730.           /* If we couldn't get a register, try to get one even if we
  1731.          might foreclose possible groups.  This may cause problems
  1732.          later, but that's better than aborting now, since it is
  1733.          possible that we will, in fact, be able to form the needed
  1734.          group even with this allocation.  */
  1735.  
  1736.           if (i >= FIRST_PSEUDO_REGISTER
  1737.           && (asm_noperands (max_needs[class] > 0
  1738.                      ? max_needs_insn[class]
  1739.                      : max_nongroups_insn[class])
  1740.               < 0))
  1741.         for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1742.           if (potential_reload_regs[i] >= 0
  1743.               && TEST_HARD_REG_BIT (reg_class_contents[class],
  1744.                         potential_reload_regs[i]))
  1745.             break;
  1746.  
  1747.           /* I should be the index in potential_reload_regs
  1748.          of the new reload reg we have found.  */
  1749.  
  1750.           if (i >= FIRST_PSEUDO_REGISTER)
  1751.         {
  1752.           /* There are no possible registers left to spill.  */
  1753.           spill_failure (max_needs[class] > 0 ? max_needs_insn[class]
  1754.                  : max_nongroups_insn[class]);
  1755.           failure = 1;
  1756.           goto failed;
  1757.         }
  1758.           else
  1759.         something_changed
  1760.           |= new_spill_reg (i, class, max_needs, max_nongroups,
  1761.                     global, dumpfile);
  1762.         }
  1763.     }
  1764.     }
  1765.  
  1766.   /* If global-alloc was run, notify it of any register eliminations we have
  1767.      done.  */
  1768.   if (global)
  1769.     for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1770.       if (ep->can_eliminate)
  1771.     mark_elimination (ep->from, ep->to);
  1772.  
  1773.   /* Insert code to save and restore call-clobbered hard regs
  1774.      around calls.  Tell if what mode to use so that we will process
  1775.      those insns in reload_as_needed if we have to.  */
  1776.  
  1777.   if (caller_save_needed)
  1778.     save_call_clobbered_regs (num_eliminable ? QImode
  1779.                   : caller_save_spill_class != NO_REGS ? HImode
  1780.                   : VOIDmode);
  1781.  
  1782.   /* If a pseudo has no hard reg, delete the insns that made the equivalence.
  1783.      If that insn didn't set the register (i.e., it copied the register to
  1784.      memory), just delete that insn instead of the equivalencing insn plus
  1785.      anything now dead.  If we call delete_dead_insn on that insn, we may
  1786.      delete the insn that actually sets the register if the register die
  1787.      there and that is incorrect.  */
  1788.  
  1789.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1790.     if (reg_renumber[i] < 0 && reg_equiv_init[i] != 0
  1791.     && GET_CODE (reg_equiv_init[i]) != NOTE)
  1792.       {
  1793.     if (reg_set_p (regno_reg_rtx[i], PATTERN (reg_equiv_init[i])))
  1794.       delete_dead_insn (reg_equiv_init[i]);
  1795.     else
  1796.       {
  1797.         PUT_CODE (reg_equiv_init[i], NOTE);
  1798.         NOTE_SOURCE_FILE (reg_equiv_init[i]) = 0;
  1799.         NOTE_LINE_NUMBER (reg_equiv_init[i]) = NOTE_INSN_DELETED;
  1800.       }
  1801.       }
  1802.  
  1803.   /* Use the reload registers where necessary
  1804.      by generating move instructions to move the must-be-register
  1805.      values into or out of the reload registers.  */
  1806.  
  1807.   if (something_needs_reloads || something_needs_elimination
  1808.       || (caller_save_needed && num_eliminable)
  1809.       || caller_save_spill_class != NO_REGS)
  1810.     reload_as_needed (first, global);
  1811.  
  1812.   /* If we were able to eliminate the frame pointer, show that it is no
  1813.      longer live at the start of any basic block.  If it is live by
  1814.      virtue of being in a pseudo, that pseudo will be marked live
  1815.      and hence the frame pointer will be known to be live via that
  1816.      pseudo.  */
  1817.  
  1818.   if (! frame_pointer_needed)
  1819.     for (i = 0; i < n_basic_blocks; i++)
  1820.       basic_block_live_at_start[i][FRAME_POINTER_REGNUM / REGSET_ELT_BITS]
  1821.     &= ~ ((REGSET_ELT_TYPE) 1 << (FRAME_POINTER_REGNUM % REGSET_ELT_BITS));
  1822.  
  1823.   reload_in_progress = 0;
  1824.  
  1825.   /* Come here (with failure set nonzero) if we can't get enough spill regs
  1826.      and we decide not to abort about it.  */
  1827.  failed:
  1828.  
  1829.   /* Now eliminate all pseudo regs by modifying them into
  1830.      their equivalent memory references.
  1831.      The REG-rtx's for the pseudos are modified in place,
  1832.      so all insns that used to refer to them now refer to memory.
  1833.  
  1834.      For a reg that has a reg_equiv_address, all those insns
  1835.      were changed by reloading so that no insns refer to it any longer;
  1836.      but the DECL_RTL of a variable decl may refer to it,
  1837.      and if so this causes the debugging info to mention the variable.  */
  1838.  
  1839.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1840.     {
  1841.       rtx addr = 0;
  1842.       int in_struct = 0;
  1843.       if (reg_equiv_mem[i])
  1844.     {
  1845.       addr = XEXP (reg_equiv_mem[i], 0);
  1846.       in_struct = MEM_IN_STRUCT_P (reg_equiv_mem[i]);
  1847.     }
  1848.       if (reg_equiv_address[i])
  1849.     addr = reg_equiv_address[i];
  1850.       if (addr)
  1851.     {
  1852.       if (reg_renumber[i] < 0)
  1853.         {
  1854.           rtx reg = regno_reg_rtx[i];
  1855.           XEXP (reg, 0) = addr;
  1856.           REG_USERVAR_P (reg) = 0;
  1857.           MEM_IN_STRUCT_P (reg) = in_struct;
  1858.           PUT_CODE (reg, MEM);
  1859.         }
  1860.       else if (reg_equiv_mem[i])
  1861.         XEXP (reg_equiv_mem[i], 0) = addr;
  1862.     }
  1863.     }
  1864.  
  1865. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  1866.   /* Make a pass over all the insns and remove death notes for things that
  1867.      are no longer registers or no longer die in the insn (e.g., an input
  1868.      and output pseudo being tied).  */
  1869.  
  1870.   for (insn = first; insn; insn = NEXT_INSN (insn))
  1871.     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  1872.       {
  1873.     rtx note, next;
  1874.  
  1875.     for (note = REG_NOTES (insn); note; note = next)
  1876.       {
  1877.         next = XEXP (note, 1);
  1878.         if (REG_NOTE_KIND (note) == REG_DEAD
  1879.         && (GET_CODE (XEXP (note, 0)) != REG
  1880.             || reg_set_p (XEXP (note, 0), PATTERN (insn))))
  1881.           remove_note (insn, note);
  1882.       }
  1883.       }
  1884. #endif
  1885.  
  1886.   /* Indicate that we no longer have known memory locations or constants.  */
  1887.   reg_equiv_constant = 0;
  1888.   reg_equiv_memory_loc = 0;
  1889.  
  1890.   return failure;
  1891. }
  1892.  
  1893. /* Nonzero if, after spilling reg REGNO for non-groups,
  1894.    it will still be possible to find a group if we still need one.  */
  1895.  
  1896. static int
  1897. possible_group_p (regno, max_groups)
  1898.      int regno;
  1899.      int *max_groups;
  1900. {
  1901.   int i;
  1902.   int class = (int) NO_REGS;
  1903.  
  1904.   for (i = 0; i < (int) N_REG_CLASSES; i++)
  1905.     if (max_groups[i] > 0)
  1906.       {
  1907.     class = i;
  1908.     break;
  1909.       }
  1910.  
  1911.   if (class == (int) NO_REGS)
  1912.     return 1;
  1913.  
  1914.   /* Consider each pair of consecutive registers.  */
  1915.   for (i = 0; i < FIRST_PSEUDO_REGISTER - 1; i++)
  1916.     {
  1917.       /* Ignore pairs that include reg REGNO.  */
  1918.       if (i == regno || i + 1 == regno)
  1919.     continue;
  1920.  
  1921.       /* Ignore pairs that are outside the class that needs the group.
  1922.      ??? Here we fail to handle the case where two different classes
  1923.      independently need groups.  But this never happens with our
  1924.      current machine descriptions.  */
  1925.       if (! (TEST_HARD_REG_BIT (reg_class_contents[class], i)
  1926.          && TEST_HARD_REG_BIT (reg_class_contents[class], i + 1)))
  1927.     continue;
  1928.  
  1929.       /* A pair of consecutive regs we can still spill does the trick.  */
  1930.       if (spill_reg_order[i] < 0 && spill_reg_order[i + 1] < 0
  1931.       && ! TEST_HARD_REG_BIT (bad_spill_regs, i)
  1932.       && ! TEST_HARD_REG_BIT (bad_spill_regs, i + 1))
  1933.     return 1;
  1934.  
  1935.       /* A pair of one already spilled and one we can spill does it
  1936.      provided the one already spilled is not otherwise reserved.  */
  1937.       if (spill_reg_order[i] < 0
  1938.       && ! TEST_HARD_REG_BIT (bad_spill_regs, i)
  1939.       && spill_reg_order[i + 1] >= 0
  1940.       && ! TEST_HARD_REG_BIT (counted_for_groups, i + 1)
  1941.       && ! TEST_HARD_REG_BIT (counted_for_nongroups, i + 1))
  1942.     return 1;
  1943.       if (spill_reg_order[i + 1] < 0
  1944.       && ! TEST_HARD_REG_BIT (bad_spill_regs, i + 1)
  1945.       && spill_reg_order[i] >= 0
  1946.       && ! TEST_HARD_REG_BIT (counted_for_groups, i)
  1947.       && ! TEST_HARD_REG_BIT (counted_for_nongroups, i))
  1948.     return 1;
  1949.     }
  1950.  
  1951.   return 0;
  1952. }
  1953.  
  1954. /* Count any groups that can be formed from the registers recently spilled.
  1955.    This is done class by class, in order of ascending class number.  */
  1956.  
  1957. static void
  1958. count_possible_groups (group_size, group_mode, max_groups)
  1959.      int *group_size, *max_groups;
  1960.      enum machine_mode *group_mode;
  1961. {
  1962.   int i;
  1963.   /* Now find all consecutive groups of spilled registers
  1964.      and mark each group off against the need for such groups.
  1965.      But don't count them against ordinary need, yet.  */
  1966.  
  1967.   for (i = 0; i < N_REG_CLASSES; i++)
  1968.     if (group_size[i] > 1)
  1969.       {
  1970.     char regmask[FIRST_PSEUDO_REGISTER];
  1971.     int j;
  1972.  
  1973.     bzero (regmask, sizeof regmask);
  1974.     /* Make a mask of all the regs that are spill regs in class I.  */
  1975.     for (j = 0; j < n_spills; j++)
  1976.       if (TEST_HARD_REG_BIT (reg_class_contents[i], spill_regs[j])
  1977.           && ! TEST_HARD_REG_BIT (counted_for_groups, spill_regs[j])
  1978.           && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1979.                       spill_regs[j]))
  1980.         regmask[spill_regs[j]] = 1;
  1981.     /* Find each consecutive group of them.  */
  1982.     for (j = 0; j < FIRST_PSEUDO_REGISTER && max_groups[i] > 0; j++)
  1983.       if (regmask[j] && j + group_size[i] <= FIRST_PSEUDO_REGISTER
  1984.           /* Next line in case group-mode for this class
  1985.          demands an even-odd pair.  */
  1986.           && HARD_REGNO_MODE_OK (j, group_mode[i]))
  1987.         {
  1988.           int k;
  1989.           for (k = 1; k < group_size[i]; k++)
  1990.         if (! regmask[j + k])
  1991.           break;
  1992.           if (k == group_size[i])
  1993.         {
  1994.           /* We found a group.  Mark it off against this class's
  1995.              need for groups, and against each superclass too.  */
  1996.           register enum reg_class *p;
  1997.           max_groups[i]--;
  1998.           p = reg_class_superclasses[i];
  1999.           while (*p != LIM_REG_CLASSES)
  2000.             max_groups[(int) *p++]--;
  2001.           /* Don't count these registers again.  */
  2002.           for (k = 0; k < group_size[i]; k++)
  2003.             SET_HARD_REG_BIT (counted_for_groups, j + k);
  2004.         }
  2005.           /* Skip to the last reg in this group.  When j is incremented
  2006.          above, it will then point to the first reg of the next
  2007.          possible group.  */
  2008.           j += k - 1;
  2009.         }
  2010.       }
  2011.  
  2012. }
  2013.  
  2014. /* ALLOCATE_MODE is a register mode that needs to be reloaded.  OTHER_MODE is
  2015.    another mode that needs to be reloaded for the same register class CLASS.
  2016.    If any reg in CLASS allows ALLOCATE_MODE but not OTHER_MODE, fail.
  2017.    ALLOCATE_MODE will never be smaller than OTHER_MODE.
  2018.  
  2019.    This code used to also fail if any reg in CLASS allows OTHER_MODE but not
  2020.    ALLOCATE_MODE.  This test is unnecessary, because we will never try to put
  2021.    something of mode ALLOCATE_MODE into an OTHER_MODE register.  Testing this
  2022.    causes unnecessary failures on machines requiring alignment of register
  2023.    groups when the two modes are different sizes, because the larger mode has
  2024.    more strict alignment rules than the smaller mode.  */
  2025.  
  2026. static int
  2027. modes_equiv_for_class_p (allocate_mode, other_mode, class)
  2028.      enum machine_mode allocate_mode, other_mode;
  2029.      enum reg_class class;
  2030. {
  2031.   register int regno;
  2032.   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
  2033.     {
  2034.       if (TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
  2035.       && HARD_REGNO_MODE_OK (regno, allocate_mode)
  2036.       && ! HARD_REGNO_MODE_OK (regno, other_mode))
  2037.     return 0;
  2038.     }
  2039.   return 1;
  2040. }
  2041.  
  2042. /* Handle the failure to find a register to spill.
  2043.    INSN should be one of the insns which needed this particular spill reg.  */
  2044.  
  2045. static void
  2046. spill_failure (insn)
  2047.      rtx insn;
  2048. {
  2049.   if (asm_noperands (PATTERN (insn)) >= 0)
  2050.     error_for_asm (insn, "`asm' needs too many reloads");
  2051.   else
  2052.     abort ();
  2053. }
  2054.  
  2055. /* Add a new register to the tables of available spill-registers
  2056.     (as well as spilling all pseudos allocated to the register).
  2057.    I is the index of this register in potential_reload_regs.
  2058.    CLASS is the regclass whose need is being satisfied.
  2059.    MAX_NEEDS and MAX_NONGROUPS are the vectors of needs,
  2060.     so that this register can count off against them.
  2061.     MAX_NONGROUPS is 0 if this register is part of a group.
  2062.    GLOBAL and DUMPFILE are the same as the args that `reload' got.  */
  2063.  
  2064. static int
  2065. new_spill_reg (i, class, max_needs, max_nongroups, global, dumpfile)
  2066.      int i;
  2067.      int class;
  2068.      int *max_needs;
  2069.      int *max_nongroups;
  2070.      int global;
  2071.      FILE *dumpfile;
  2072. {
  2073.   register enum reg_class *p;
  2074.   int val;
  2075.   int regno = potential_reload_regs[i];
  2076.  
  2077.   if (i >= FIRST_PSEUDO_REGISTER)
  2078.     abort ();    /* Caller failed to find any register.  */
  2079.  
  2080.   if (fixed_regs[regno] || TEST_HARD_REG_BIT (forbidden_regs, regno))
  2081.     fatal ("fixed or forbidden register was spilled.\n\
  2082. This may be due to a compiler bug or to impossible asm statements.");
  2083.  
  2084.   /* Make reg REGNO an additional reload reg.  */
  2085.  
  2086.   potential_reload_regs[i] = -1;
  2087.   spill_regs[n_spills] = regno;
  2088.   spill_reg_order[regno] = n_spills;
  2089.   if (dumpfile)
  2090.     fprintf (dumpfile, "Spilling reg %d.\n", spill_regs[n_spills]);
  2091.  
  2092.   /* Clear off the needs we just satisfied.  */
  2093.  
  2094.   max_needs[class]--;
  2095.   p = reg_class_superclasses[class];
  2096.   while (*p != LIM_REG_CLASSES)
  2097.     max_needs[(int) *p++]--;
  2098.  
  2099.   if (max_nongroups && max_nongroups[class] > 0)
  2100.     {
  2101.       SET_HARD_REG_BIT (counted_for_nongroups, regno);
  2102.       max_nongroups[class]--;
  2103.       p = reg_class_superclasses[class];
  2104.       while (*p != LIM_REG_CLASSES)
  2105.     max_nongroups[(int) *p++]--;
  2106.     }
  2107.  
  2108.   /* Spill every pseudo reg that was allocated to this reg
  2109.      or to something that overlaps this reg.  */
  2110.  
  2111.   val = spill_hard_reg (spill_regs[n_spills], global, dumpfile, 0);
  2112.  
  2113.   /* If there are some registers still to eliminate and this register
  2114.      wasn't ever used before, additional stack space may have to be
  2115.      allocated to store this register.  Thus, we may have changed the offset
  2116.      between the stack and frame pointers, so mark that something has changed.
  2117.      (If new pseudos were spilled, thus requiring more space, VAL would have
  2118.      been set non-zero by the call to spill_hard_reg above since additional
  2119.      reloads may be needed in that case.
  2120.  
  2121.      One might think that we need only set VAL to 1 if this is a call-used
  2122.      register.  However, the set of registers that must be saved by the
  2123.      prologue is not identical to the call-used set.  For example, the
  2124.      register used by the call insn for the return PC is a call-used register,
  2125.      but must be saved by the prologue.  */
  2126.   if (num_eliminable && ! regs_ever_live[spill_regs[n_spills]])
  2127.     val = 1;
  2128.  
  2129.   regs_ever_live[spill_regs[n_spills]] = 1;
  2130.   n_spills++;
  2131.  
  2132.   return val;
  2133. }
  2134.  
  2135. /* Delete an unneeded INSN and any previous insns who sole purpose is loading
  2136.    data that is dead in INSN.  */
  2137.  
  2138. static void
  2139. delete_dead_insn (insn)
  2140.      rtx insn;
  2141. {
  2142.   rtx prev = prev_real_insn (insn);
  2143.   rtx prev_dest;
  2144.  
  2145.   /* If the previous insn sets a register that dies in our insn, delete it
  2146.      too.  */
  2147.   if (prev && GET_CODE (PATTERN (prev)) == SET
  2148.       && (prev_dest = SET_DEST (PATTERN (prev)), GET_CODE (prev_dest) == REG)
  2149.       && reg_mentioned_p (prev_dest, PATTERN (insn))
  2150.       && find_regno_note (insn, REG_DEAD, REGNO (prev_dest)))
  2151.     delete_dead_insn (prev);
  2152.  
  2153.   PUT_CODE (insn, NOTE);
  2154.   NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  2155.   NOTE_SOURCE_FILE (insn) = 0;
  2156. }
  2157.  
  2158. /* Modify the home of pseudo-reg I.
  2159.    The new home is present in reg_renumber[I].
  2160.  
  2161.    FROM_REG may be the hard reg that the pseudo-reg is being spilled from;
  2162.    or it may be -1, meaning there is none or it is not relevant.
  2163.    This is used so that all pseudos spilled from a given hard reg
  2164.    can share one stack slot.  */
  2165.  
  2166. static void
  2167. alter_reg (i, from_reg)
  2168.      register int i;
  2169.      int from_reg;
  2170. {
  2171.   /* When outputting an inline function, this can happen
  2172.      for a reg that isn't actually used.  */
  2173.   if (regno_reg_rtx[i] == 0)
  2174.     return;
  2175.  
  2176.   /* If the reg got changed to a MEM at rtl-generation time,
  2177.      ignore it.  */
  2178.   if (GET_CODE (regno_reg_rtx[i]) != REG)
  2179.     return;
  2180.  
  2181.   /* Modify the reg-rtx to contain the new hard reg
  2182.      number or else to contain its pseudo reg number.  */
  2183.   REGNO (regno_reg_rtx[i])
  2184.     = reg_renumber[i] >= 0 ? reg_renumber[i] : i;
  2185.  
  2186.   /* If we have a pseudo that is needed but has no hard reg or equivalent,
  2187.      allocate a stack slot for it.  */
  2188.  
  2189.   if (reg_renumber[i] < 0
  2190.       && reg_n_refs[i] > 0
  2191.       && reg_equiv_constant[i] == 0
  2192.       && reg_equiv_memory_loc[i] == 0)
  2193.     {
  2194.       register rtx x;
  2195.       int inherent_size = PSEUDO_REGNO_BYTES (i);
  2196.       int total_size = MAX (inherent_size, reg_max_ref_width[i]);
  2197.       int adjust = 0;
  2198.  
  2199.       /* Each pseudo reg has an inherent size which comes from its own mode,
  2200.      and a total size which provides room for paradoxical subregs
  2201.      which refer to the pseudo reg in wider modes.
  2202.  
  2203.      We can use a slot already allocated if it provides both
  2204.      enough inherent space and enough total space.
  2205.      Otherwise, we allocate a new slot, making sure that it has no less
  2206.      inherent space, and no less total space, then the previous slot.  */
  2207.       if (from_reg == -1)
  2208.     {
  2209.       /* No known place to spill from => no slot to reuse.  */
  2210.       x = assign_stack_local (GET_MODE (regno_reg_rtx[i]), total_size, -1);
  2211. #if BYTES_BIG_ENDIAN
  2212.       /* Cancel the  big-endian correction done in assign_stack_local.
  2213.          Get the address of the beginning of the slot.
  2214.          This is so we can do a big-endian correction unconditionally
  2215.          below.  */
  2216.       adjust = inherent_size - total_size;
  2217. #endif
  2218.     }
  2219.       /* Reuse a stack slot if possible.  */
  2220.       else if (spill_stack_slot[from_reg] != 0
  2221.            && spill_stack_slot_width[from_reg] >= total_size
  2222.            && (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  2223.            >= inherent_size))
  2224.     x = spill_stack_slot[from_reg];
  2225.       /* Allocate a bigger slot.  */
  2226.       else
  2227.     {
  2228.       /* Compute maximum size needed, both for inherent size
  2229.          and for total size.  */
  2230.       enum machine_mode mode = GET_MODE (regno_reg_rtx[i]);
  2231.       if (spill_stack_slot[from_reg])
  2232.         {
  2233.           if (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  2234.           > inherent_size)
  2235.         mode = GET_MODE (spill_stack_slot[from_reg]);
  2236.           if (spill_stack_slot_width[from_reg] > total_size)
  2237.         total_size = spill_stack_slot_width[from_reg];
  2238.         }
  2239.       /* Make a slot with that size.  */
  2240.       x = assign_stack_local (mode, total_size, -1);
  2241. #if BYTES_BIG_ENDIAN
  2242.       /* Cancel the  big-endian correction done in assign_stack_local.
  2243.          Get the address of the beginning of the slot.
  2244.          This is so we can do a big-endian correction unconditionally
  2245.          below.  */
  2246.       adjust = GET_MODE_SIZE (mode) - total_size;
  2247. #endif
  2248.       spill_stack_slot[from_reg] = x;
  2249.       spill_stack_slot_width[from_reg] = total_size;
  2250.     }
  2251.  
  2252. #if BYTES_BIG_ENDIAN
  2253.       /* On a big endian machine, the "address" of the slot
  2254.      is the address of the low part that fits its inherent mode.  */
  2255.       if (inherent_size < total_size)
  2256.     adjust += (total_size - inherent_size);
  2257. #endif /* BYTES_BIG_ENDIAN */
  2258.  
  2259.       /* If we have any adjustment to make, or if the stack slot is the
  2260.      wrong mode, make a new stack slot.  */
  2261.       if (adjust != 0 || GET_MODE (x) != GET_MODE (regno_reg_rtx[i]))
  2262.     {
  2263.       x = gen_rtx (MEM, GET_MODE (regno_reg_rtx[i]),
  2264.                plus_constant (XEXP (x, 0), adjust));
  2265.       RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[i]);
  2266.     }
  2267.  
  2268.       /* Save the stack slot for later.   */
  2269.       reg_equiv_memory_loc[i] = x;
  2270.     }
  2271. }
  2272.  
  2273. /* Mark the slots in regs_ever_live for the hard regs
  2274.    used by pseudo-reg number REGNO.  */
  2275.  
  2276. void
  2277. mark_home_live (regno)
  2278.      int regno;
  2279. {
  2280.   register int i, lim;
  2281.   i = reg_renumber[regno];
  2282.   if (i < 0)
  2283.     return;
  2284.   lim = i + HARD_REGNO_NREGS (i, PSEUDO_REGNO_MODE (regno));
  2285.   while (i < lim)
  2286.     regs_ever_live[i++] = 1;
  2287. }
  2288.  
  2289. /* This function handles the tracking of elimination offsets around branches.
  2290.  
  2291.    X is a piece of RTL being scanned.
  2292.  
  2293.    INSN is the insn that it came from, if any.
  2294.  
  2295.    INITIAL_P is non-zero if we are to set the offset to be the initial
  2296.    offset and zero if we are setting the offset of the label to be the
  2297.    current offset.  */
  2298.  
  2299. static void
  2300. set_label_offsets (x, insn, initial_p)
  2301.      rtx x;
  2302.      rtx insn;
  2303.      int initial_p;
  2304. {
  2305.   enum rtx_code code = GET_CODE (x);
  2306.   rtx tem;
  2307.   int i;
  2308.   struct elim_table *p;
  2309.  
  2310.   switch (code)
  2311.     {
  2312.     case LABEL_REF:
  2313.       if (LABEL_REF_NONLOCAL_P (x))
  2314.     return;
  2315.  
  2316.       x = XEXP (x, 0);
  2317.  
  2318.       /* ... fall through ... */
  2319.  
  2320.     case CODE_LABEL:
  2321.       /* If we know nothing about this label, set the desired offsets.  Note
  2322.      that this sets the offset at a label to be the offset before a label
  2323.      if we don't know anything about the label.  This is not correct for
  2324.      the label after a BARRIER, but is the best guess we can make.  If
  2325.      we guessed wrong, we will suppress an elimination that might have
  2326.      been possible had we been able to guess correctly.  */
  2327.  
  2328.       if (! offsets_known_at[CODE_LABEL_NUMBER (x)])
  2329.     {
  2330.       for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2331.         offsets_at[CODE_LABEL_NUMBER (x)][i]
  2332.           = (initial_p ? reg_eliminate[i].initial_offset
  2333.          : reg_eliminate[i].offset);
  2334.       offsets_known_at[CODE_LABEL_NUMBER (x)] = 1;
  2335.     }
  2336.  
  2337.       /* Otherwise, if this is the definition of a label and it is
  2338.      preceded by a BARRIER, set our offsets to the known offset of
  2339.      that label.  */
  2340.  
  2341.       else if (x == insn
  2342.            && (tem = prev_nonnote_insn (insn)) != 0
  2343.            && GET_CODE (tem) == BARRIER)
  2344.     {
  2345.       num_not_at_initial_offset = 0;
  2346.       for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2347.         {
  2348.           reg_eliminate[i].offset = reg_eliminate[i].previous_offset
  2349.         = offsets_at[CODE_LABEL_NUMBER (x)][i];
  2350.           if (reg_eliminate[i].can_eliminate
  2351.           && (reg_eliminate[i].offset
  2352.               != reg_eliminate[i].initial_offset))
  2353.         num_not_at_initial_offset++;
  2354.         }
  2355.     }
  2356.  
  2357.       else
  2358.     /* If neither of the above cases is true, compare each offset
  2359.        with those previously recorded and suppress any eliminations
  2360.        where the offsets disagree.  */
  2361.  
  2362.     for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2363.       if (offsets_at[CODE_LABEL_NUMBER (x)][i]
  2364.           != (initial_p ? reg_eliminate[i].initial_offset
  2365.           : reg_eliminate[i].offset))
  2366.         reg_eliminate[i].can_eliminate = 0;
  2367.  
  2368.       return;
  2369.  
  2370.     case JUMP_INSN:
  2371.       set_label_offsets (PATTERN (insn), insn, initial_p);
  2372.  
  2373.       /* ... fall through ... */
  2374.  
  2375.     case INSN:
  2376.     case CALL_INSN:
  2377.       /* Any labels mentioned in REG_LABEL notes can be branched to indirectly
  2378.      and hence must have all eliminations at their initial offsets.  */
  2379.       for (tem = REG_NOTES (x); tem; tem = XEXP (tem, 1))
  2380.     if (REG_NOTE_KIND (tem) == REG_LABEL)
  2381.       set_label_offsets (XEXP (tem, 0), insn, 1);
  2382.       return;
  2383.  
  2384.     case ADDR_VEC:
  2385.     case ADDR_DIFF_VEC:
  2386.       /* Each of the labels in the address vector must be at their initial
  2387.      offsets.  We want the first first for ADDR_VEC and the second
  2388.      field for ADDR_DIFF_VEC.  */
  2389.  
  2390.       for (i = 0; i < XVECLEN (x, code == ADDR_DIFF_VEC); i++)
  2391.     set_label_offsets (XVECEXP (x, code == ADDR_DIFF_VEC, i),
  2392.                insn, initial_p);
  2393.       return;
  2394.  
  2395.     case SET:
  2396.       /* We only care about setting PC.  If the source is not RETURN,
  2397.      IF_THEN_ELSE, or a label, disable any eliminations not at
  2398.      their initial offsets.  Similarly if any arm of the IF_THEN_ELSE
  2399.      isn't one of those possibilities.  For branches to a label,
  2400.      call ourselves recursively.
  2401.  
  2402.      Note that this can disable elimination unnecessarily when we have
  2403.      a non-local goto since it will look like a non-constant jump to
  2404.      someplace in the current function.  This isn't a significant
  2405.      problem since such jumps will normally be when all elimination
  2406.      pairs are back to their initial offsets.  */
  2407.  
  2408.       if (SET_DEST (x) != pc_rtx)
  2409.     return;
  2410.  
  2411.       switch (GET_CODE (SET_SRC (x)))
  2412.     {
  2413.     case PC:
  2414.     case RETURN:
  2415.       return;
  2416.  
  2417.     case LABEL_REF:
  2418.       set_label_offsets (XEXP (SET_SRC (x), 0), insn, initial_p);
  2419.       return;
  2420.  
  2421.     case IF_THEN_ELSE:
  2422.       tem = XEXP (SET_SRC (x), 1);
  2423.       if (GET_CODE (tem) == LABEL_REF)
  2424.         set_label_offsets (XEXP (tem, 0), insn, initial_p);
  2425.       else if (GET_CODE (tem) != PC && GET_CODE (tem) != RETURN)
  2426.         break;
  2427.  
  2428.       tem = XEXP (SET_SRC (x), 2);
  2429.       if (GET_CODE (tem) == LABEL_REF)
  2430.         set_label_offsets (XEXP (tem, 0), insn, initial_p);
  2431.       else if (GET_CODE (tem) != PC && GET_CODE (tem) != RETURN)
  2432.         break;
  2433.       return;
  2434.     }
  2435.  
  2436.       /* If we reach here, all eliminations must be at their initial
  2437.      offset because we are doing a jump to a variable address.  */
  2438.       for (p = reg_eliminate; p < ®_eliminate[NUM_ELIMINABLE_REGS]; p++)
  2439.     if (p->offset != p->initial_offset)
  2440.       p->can_eliminate = 0;
  2441.     }
  2442. }
  2443.  
  2444. /* Used for communication between the next two function to properly share
  2445.    the vector for an ASM_OPERANDS.  */
  2446.  
  2447. static struct rtvec_def *old_asm_operands_vec, *new_asm_operands_vec;
  2448.  
  2449. /* Scan X and replace any eliminable registers (such as fp) with a
  2450.    replacement (such as sp), plus an offset.
  2451.  
  2452.    MEM_MODE is the mode of an enclosing MEM.  We need this to know how
  2453.    much to adjust a register for, e.g., PRE_DEC.  Also, if we are inside a
  2454.    MEM, we are allowed to replace a sum of a register and the constant zero
  2455.    with the register, which we cannot do outside a MEM.  In addition, we need
  2456.    to record the fact that a register is referenced outside a MEM.
  2457.  
  2458.    If INSN is nonzero, it is the insn containing X.  If we replace a REG
  2459.    in a SET_DEST with an equivalent MEM and INSN is non-zero, write a
  2460.    CLOBBER of the pseudo after INSN so find_equiv_regs will know that
  2461.    that the REG is being modified.
  2462.  
  2463.    If we see a modification to a register we know about, take the
  2464.    appropriate action (see case SET, below).
  2465.  
  2466.    REG_EQUIV_MEM and REG_EQUIV_ADDRESS contain address that have had
  2467.    replacements done assuming all offsets are at their initial values.  If
  2468.    they are not, or if REG_EQUIV_ADDRESS is nonzero for a pseudo we
  2469.    encounter, return the actual location so that find_reloads will do
  2470.    the proper thing.  */
  2471.  
  2472. rtx
  2473. eliminate_regs (x, mem_mode, insn)
  2474.      rtx x;
  2475.      enum machine_mode mem_mode;
  2476.      rtx insn;
  2477. {
  2478.   enum rtx_code code = GET_CODE (x);
  2479.   struct elim_table *ep;
  2480.   int regno;
  2481.   rtx new;
  2482.   int i, j;
  2483.   char *fmt;
  2484.   int copied = 0;
  2485.  
  2486.   switch (code)
  2487.     {
  2488.     case CONST_INT:
  2489.     case CONST_DOUBLE:
  2490.     case CONST:
  2491.     case SYMBOL_REF:
  2492.     case CODE_LABEL:
  2493.     case PC:
  2494.     case CC0:
  2495.     case ASM_INPUT:
  2496.     case ADDR_VEC:
  2497.     case ADDR_DIFF_VEC:
  2498.     case RETURN:
  2499.       return x;
  2500.  
  2501.     case REG:
  2502.       regno = REGNO (x);
  2503.  
  2504.       /* First handle the case where we encounter a bare register that
  2505.      is eliminable.  Replace it with a PLUS.  */
  2506.       if (regno < FIRST_PSEUDO_REGISTER)
  2507.     {
  2508.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2509.            ep++)
  2510.         if (ep->from_rtx == x && ep->can_eliminate)
  2511.           {
  2512.         if (! mem_mode)
  2513.           ep->ref_outside_mem = 1;
  2514.         return plus_constant (ep->to_rtx, ep->previous_offset);
  2515.           }
  2516.  
  2517.     }
  2518.       else if (reg_equiv_memory_loc && reg_equiv_memory_loc[regno]
  2519.            && (reg_equiv_address[regno] || num_not_at_initial_offset))
  2520.     {
  2521.       /* In this case, find_reloads would attempt to either use an
  2522.          incorrect address (if something is not at its initial offset)
  2523.          or substitute an replaced address into an insn (which loses
  2524.          if the offset is changed by some later action).  So we simply
  2525.          return the replaced stack slot (assuming it is changed by
  2526.          elimination) and ignore the fact that this is actually a
  2527.          reference to the pseudo.  Ensure we make a copy of the
  2528.          address in case it is shared.  */
  2529.       new = eliminate_regs (reg_equiv_memory_loc[regno],
  2530.                 mem_mode, NULL_RTX);
  2531.       if (new != reg_equiv_memory_loc[regno])
  2532.         return copy_rtx (new);
  2533.     }
  2534.       return x;
  2535.  
  2536.     case PLUS:
  2537.       /* If this is the sum of an eliminable register and a constant, rework
  2538.      the sum.   */
  2539.       if (GET_CODE (XEXP (x, 0)) == REG
  2540.       && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
  2541.       && CONSTANT_P (XEXP (x, 1)))
  2542.     {
  2543.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2544.            ep++)
  2545.         if (ep->from_rtx == XEXP (x, 0) && ep->can_eliminate)
  2546.           {
  2547.         if (! mem_mode)
  2548.           ep->ref_outside_mem = 1;
  2549.  
  2550.         /* The only time we want to replace a PLUS with a REG (this
  2551.            occurs when the constant operand of the PLUS is the negative
  2552.            of the offset) is when we are inside a MEM.  We won't want
  2553.            to do so at other times because that would change the
  2554.            structure of the insn in a way that reload can't handle.
  2555.            We special-case the commonest situation in
  2556.            eliminate_regs_in_insn, so just replace a PLUS with a
  2557.            PLUS here, unless inside a MEM.  */
  2558.         if (mem_mode != 0 && GET_CODE (XEXP (x, 1)) == CONST_INT
  2559.             && INTVAL (XEXP (x, 1)) == - ep->previous_offset)
  2560.           return ep->to_rtx;
  2561.         else
  2562.           return gen_rtx (PLUS, DPmode, ep->to_rtx,
  2563.                   plus_constant (XEXP (x, 1),
  2564.                          ep->previous_offset));
  2565.           }
  2566.  
  2567.       /* If the register is not eliminable, we are done since the other
  2568.          operand is a constant.  */
  2569.       return x;
  2570.     }
  2571.  
  2572.       /* If this is part of an address, we want to bring any constant to the
  2573.      outermost PLUS.  We will do this by doing register replacement in
  2574.      our operands and seeing if a constant shows up in one of them.
  2575.  
  2576.      We assume here this is part of an address (or a "load address" insn)
  2577.      since an eliminable register is not likely to appear in any other
  2578.      context.
  2579.  
  2580.      If we have (plus (eliminable) (reg)), we want to produce
  2581.      (plus (plus (replacement) (reg) (const))).  If this was part of a
  2582.      normal add insn, (plus (replacement) (reg)) will be pushed as a
  2583.      reload.  This is the desired action.  */
  2584.  
  2585.       {
  2586.     rtx new0 = eliminate_regs (XEXP (x, 0), mem_mode, NULL_RTX);
  2587.     rtx new1 = eliminate_regs (XEXP (x, 1), mem_mode, NULL_RTX);
  2588.  
  2589.     if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
  2590.       {
  2591.         /* If one side is a PLUS and the other side is a pseudo that
  2592.            didn't get a hard register but has a reg_equiv_constant,
  2593.            we must replace the constant here since it may no longer
  2594.            be in the position of any operand.  */
  2595.         if (GET_CODE (new0) == PLUS && GET_CODE (new1) == REG
  2596.         && REGNO (new1) >= FIRST_PSEUDO_REGISTER
  2597.         && reg_renumber[REGNO (new1)] < 0
  2598.         && reg_equiv_constant != 0
  2599.         && reg_equiv_constant[REGNO (new1)] != 0)
  2600.           new1 = reg_equiv_constant[REGNO (new1)];
  2601.         else if (GET_CODE (new1) == PLUS && GET_CODE (new0) == REG
  2602.              && REGNO (new0) >= FIRST_PSEUDO_REGISTER
  2603.              && reg_renumber[REGNO (new0)] < 0
  2604.              && reg_equiv_constant[REGNO (new0)] != 0)
  2605.           new0 = reg_equiv_constant[REGNO (new0)];
  2606.  
  2607.         new = form_sum (new0, new1);
  2608.  
  2609.         /* As above, if we are not inside a MEM we do not want to
  2610.            turn a PLUS into something else.  We might try to do so here
  2611.            for an addition of 0 if we aren't optimizing.  */
  2612.         if (! mem_mode && GET_CODE (new) != PLUS)
  2613.           return gen_rtx (PLUS, GET_MODE (x), new, const0_rtx);
  2614.         else
  2615.           return new;
  2616.       }
  2617.       }
  2618.       return x;
  2619.  
  2620.     case EXPR_LIST:
  2621.       /* If we have something in XEXP (x, 0), the usual case, eliminate it.  */
  2622.       if (XEXP (x, 0))
  2623.     {
  2624.       new = eliminate_regs (XEXP (x, 0), mem_mode, NULL_RTX);
  2625.       if (new != XEXP (x, 0))
  2626.         x = gen_rtx (EXPR_LIST, REG_NOTE_KIND (x), new, XEXP (x, 1));
  2627.     }
  2628.  
  2629.       /* ... fall through ... */
  2630.  
  2631.     case INSN_LIST:
  2632.       /* Now do eliminations in the rest of the chain.  If this was
  2633.      an EXPR_LIST, this might result in allocating more memory than is
  2634.      strictly needed, but it simplifies the code.  */
  2635.       if (XEXP (x, 1))
  2636.     {
  2637.       new = eliminate_regs (XEXP (x, 1), mem_mode, NULL_RTX);
  2638.       if (new != XEXP (x, 1))
  2639.         return gen_rtx (INSN_LIST, GET_MODE (x), XEXP (x, 0), new);
  2640.     }
  2641.       return x;
  2642.  
  2643.     case CALL:
  2644.     case COMPARE:
  2645.     case MINUS:
  2646.     case MULT:
  2647.     case DIV:      case UDIV:
  2648.     case MOD:      case UMOD:
  2649.     case AND:      case IOR:      case XOR:
  2650.     case LSHIFT:   case ASHIFT:   case ROTATE:
  2651.     case ASHIFTRT: case LSHIFTRT: case ROTATERT:
  2652.     case NE:       case EQ:
  2653.     case GE:       case GT:       case GEU:    case GTU:
  2654.     case LE:       case LT:       case LEU:    case LTU:
  2655.       {
  2656.     rtx new0 = eliminate_regs (XEXP (x, 0), mem_mode, NULL_RTX);
  2657.     rtx new1
  2658.       = XEXP (x, 1) ? eliminate_regs (XEXP (x, 1), mem_mode, NULL_RTX) : 0;
  2659.  
  2660.     if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
  2661.       return gen_rtx (code, GET_MODE (x), new0, new1);
  2662.       }
  2663.       return x;
  2664.  
  2665.     case PRE_INC:
  2666.     case POST_INC:
  2667.     case PRE_DEC:
  2668.     case POST_DEC:
  2669.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2670.     if (ep->to_rtx == XEXP (x, 0))
  2671.       {
  2672.         if (code == PRE_DEC || code == POST_DEC)
  2673.           ep->offset += GET_MODE_SIZE (mem_mode);
  2674.         else
  2675.           ep->offset -= GET_MODE_SIZE (mem_mode);
  2676.       }
  2677.  
  2678.       /* Fall through to generic unary operation case.  */
  2679.     case USE:
  2680.     case STRICT_LOW_PART:
  2681.     case NEG:          case NOT:
  2682.     case SIGN_EXTEND:  case ZERO_EXTEND:
  2683.     case TRUNCATE:     case FLOAT_EXTEND: case FLOAT_TRUNCATE:
  2684.     case FLOAT:        case FIX:
  2685.     case UNSIGNED_FIX: case UNSIGNED_FLOAT:
  2686.     case ABS:
  2687.     case SQRT:
  2688.     case FFS:
  2689.       new = eliminate_regs (XEXP (x, 0), mem_mode, NULL_RTX);
  2690.       if (new != XEXP (x, 0))
  2691.     return gen_rtx (code, GET_MODE (x), new);
  2692.       return x;
  2693.  
  2694.     case SUBREG:
  2695.       /* Similar to above processing, but preserve SUBREG_WORD.
  2696.      Convert (subreg (mem)) to (mem) if not paradoxical.
  2697.      Also, if we have a non-paradoxical (subreg (pseudo)) and the
  2698.      pseudo didn't get a hard reg, we must replace this with the
  2699.      eliminated version of the memory location because push_reloads
  2700.      may do the replacement in certain circumstances.  */
  2701.       if (GET_CODE (SUBREG_REG (x)) == REG
  2702.       && (GET_MODE_SIZE (GET_MODE (x))
  2703.           <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  2704.       && reg_equiv_memory_loc != 0
  2705.       && reg_equiv_memory_loc[REGNO (SUBREG_REG (x))] != 0)
  2706.     {
  2707.       new = eliminate_regs (reg_equiv_memory_loc[REGNO (SUBREG_REG (x))],
  2708.                 mem_mode, NULL_RTX);
  2709.  
  2710.       /* If we didn't change anything, we must retain the pseudo.  */
  2711.       if (new == reg_equiv_memory_loc[REGNO (SUBREG_REG (x))])
  2712.         new = XEXP (x, 0);
  2713.       else
  2714.         /* Otherwise, ensure NEW isn't shared in case we have to reload
  2715.            it.  */
  2716.         new = copy_rtx (new);
  2717.     }
  2718.       else
  2719.     new = eliminate_regs (SUBREG_REG (x), mem_mode, NULL_RTX);
  2720.  
  2721.       if (new != XEXP (x, 0))
  2722.     {
  2723.       if (GET_CODE (new) == MEM
  2724.           && (GET_MODE_SIZE (GET_MODE (x))
  2725.           <= GET_MODE_SIZE (GET_MODE (new))))
  2726.         {
  2727.           int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  2728.           enum machine_mode mode = GET_MODE (x);
  2729.  
  2730. #if BYTES_BIG_ENDIAN
  2731.           offset += (MIN (UNITS_PER_WORD,
  2732.                   GET_MODE_SIZE (GET_MODE (new)))
  2733.              - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  2734. #endif
  2735.  
  2736.           PUT_MODE (new, mode);
  2737.           XEXP (new, 0) = plus_constant (XEXP (new, 0), offset);
  2738.           return new;
  2739.         }
  2740.       else
  2741.         return gen_rtx (SUBREG, GET_MODE (x), new, SUBREG_WORD (x));
  2742.     }
  2743.  
  2744.       return x;
  2745.  
  2746.     case CLOBBER:
  2747.       /* If clobbering a register that is the replacement register for an
  2748.      elimination we still think can be performed, note that it cannot
  2749.      be performed.  Otherwise, we need not be concerned about it.  */
  2750.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2751.     if (ep->to_rtx == XEXP (x, 0))
  2752.       ep->can_eliminate = 0;
  2753.  
  2754.       return x;
  2755.  
  2756.     case ASM_OPERANDS:
  2757.       {
  2758.     rtx *temp_vec;
  2759.     /* Properly handle sharing input and constraint vectors.  */
  2760.     if (ASM_OPERANDS_INPUT_VEC (x) != old_asm_operands_vec)
  2761.       {
  2762.         /* When we come to a new vector not seen before,
  2763.            scan all its elements; keep the old vector if none
  2764.            of them changes; otherwise, make a copy.  */
  2765.         old_asm_operands_vec = ASM_OPERANDS_INPUT_VEC (x);
  2766.         temp_vec = (rtx *) alloca (XVECLEN (x, 3) * sizeof (rtx));
  2767.         for (i = 0; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
  2768.           temp_vec[i] = eliminate_regs (ASM_OPERANDS_INPUT (x, i),
  2769.                         mem_mode, NULL_RTX);
  2770.  
  2771.         for (i = 0; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
  2772.           if (temp_vec[i] != ASM_OPERANDS_INPUT (x, i))
  2773.         break;
  2774.  
  2775.         if (i == ASM_OPERANDS_INPUT_LENGTH (x))
  2776.           new_asm_operands_vec = old_asm_operands_vec;
  2777.         else
  2778.           new_asm_operands_vec
  2779.         = gen_rtvec_v (ASM_OPERANDS_INPUT_LENGTH (x), temp_vec);
  2780.       }
  2781.  
  2782.     /* If we had to copy the vector, copy the entire ASM_OPERANDS.  */
  2783.     if (new_asm_operands_vec == old_asm_operands_vec)
  2784.       return x;
  2785.  
  2786.     new = gen_rtx (ASM_OPERANDS, VOIDmode, ASM_OPERANDS_TEMPLATE (x),
  2787.                ASM_OPERANDS_OUTPUT_CONSTRAINT (x),
  2788.                ASM_OPERANDS_OUTPUT_IDX (x), new_asm_operands_vec,
  2789.                ASM_OPERANDS_INPUT_CONSTRAINT_VEC (x),
  2790.                ASM_OPERANDS_SOURCE_FILE (x),
  2791.                ASM_OPERANDS_SOURCE_LINE (x));
  2792.     new->volatil = x->volatil;
  2793.     return new;
  2794.       }
  2795.  
  2796.     case SET:
  2797.       /* Check for setting a register that we know about.  */
  2798.       if (GET_CODE (SET_DEST (x)) == REG)
  2799.     {
  2800.       /* See if this is setting the replacement register for an
  2801.          elimination.
  2802.  
  2803.          If DEST is the frame pointer, we do nothing because we assume that
  2804.          all assignments to the frame pointer are for non-local gotos and
  2805.          are being done at a time when they are valid and do not disturb
  2806.          anything else.  Some machines want to eliminate a fake argument
  2807.          pointer with either the frame or stack pointer.  Assignments to
  2808.          the frame pointer must not prevent this elimination.  */
  2809.  
  2810.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2811.            ep++)
  2812.         if (ep->to_rtx == SET_DEST (x)
  2813.         && SET_DEST (x) != frame_pointer_rtx)
  2814.           {
  2815.         /* If it is being incremented, adjust the offset.  Otherwise,
  2816.            this elimination can't be done.  */
  2817.         rtx src = SET_SRC (x);
  2818.  
  2819.         if (GET_CODE (src) == PLUS
  2820.             && XEXP (src, 0) == SET_DEST (x)
  2821.             && GET_CODE (XEXP (src, 1)) == CONST_INT)
  2822.           ep->offset -= INTVAL (XEXP (src, 1));
  2823.         else
  2824.           ep->can_eliminate = 0;
  2825.           }
  2826.  
  2827.       /* Now check to see we are assigning to a register that can be
  2828.          eliminated.  If so, it must be as part of a PARALLEL, since we
  2829.          will not have been called if this is a single SET.  So indicate
  2830.          that we can no longer eliminate this reg.  */
  2831.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2832.            ep++)
  2833.         if (ep->from_rtx == SET_DEST (x) && ep->can_eliminate)
  2834.           ep->can_eliminate = 0;
  2835.     }
  2836.  
  2837.       /* Now avoid the loop below in this common case.  */
  2838.       {
  2839.     rtx new0 = eliminate_regs (SET_DEST (x), 0, NULL_RTX);
  2840.     rtx new1 = eliminate_regs (SET_SRC (x), 0, NULL_RTX);
  2841.  
  2842.     /* If SET_DEST changed from a REG to a MEM and INSN is non-zero,
  2843.        write a CLOBBER insn.  */
  2844.     if (GET_CODE (SET_DEST (x)) == REG && GET_CODE (new0) == MEM
  2845.         && insn != 0)
  2846.       emit_insn_after (gen_rtx (CLOBBER, VOIDmode, SET_DEST (x)), insn);
  2847.  
  2848.     if (new0 != SET_DEST (x) || new1 != SET_SRC (x))
  2849.       return gen_rtx (SET, VOIDmode, new0, new1);
  2850.       }
  2851.  
  2852.       return x;
  2853.  
  2854.     case MEM:
  2855.       /* Our only special processing is to pass the mode of the MEM to our
  2856.      recursive call and copy the flags.  While we are here, handle this
  2857.      case more efficiently.  */
  2858.       new = eliminate_regs (XEXP (x, 0), GET_MODE (x), NULL_RTX);
  2859.       if (new != XEXP (x, 0))
  2860.     {
  2861.       new = gen_rtx (MEM, GET_MODE (x), new);
  2862.       new->volatil = x->volatil;
  2863.       new->unchanging = x->unchanging;
  2864.       new->in_struct = x->in_struct;
  2865.       return new;
  2866.     }
  2867.       else
  2868.     return x;
  2869.     }
  2870.  
  2871.   /* Process each of our operands recursively.  If any have changed, make a
  2872.      copy of the rtx.  */
  2873.   fmt = GET_RTX_FORMAT (code);
  2874.   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
  2875.     {
  2876.       if (*fmt == 'e')
  2877.     {
  2878.       new = eliminate_regs (XEXP (x, i), mem_mode, NULL_RTX);
  2879.       if (new != XEXP (x, i) && ! copied)
  2880.         {
  2881.           rtx new_x = rtx_alloc (code);
  2882.           bcopy (x, new_x, (sizeof (*new_x) - sizeof (new_x->fld)
  2883.                 + (sizeof (new_x->fld[0])
  2884.                    * GET_RTX_LENGTH (code))));
  2885.           x = new_x;
  2886.           copied = 1;
  2887.         }
  2888.       XEXP (x, i) = new;
  2889.     }
  2890.       else if (*fmt == 'E')
  2891.     {
  2892.       int copied_vec = 0;
  2893.       for (j = 0; j < XVECLEN (x, i); j++)
  2894.         {
  2895.           new = eliminate_regs (XVECEXP (x, i, j), mem_mode, insn);
  2896.           if (new != XVECEXP (x, i, j) && ! copied_vec)
  2897.         {
  2898.           rtvec new_v = gen_rtvec_v (XVECLEN (x, i),
  2899.                          &XVECEXP (x, i, 0));
  2900.           if (! copied)
  2901.             {
  2902.               rtx new_x = rtx_alloc (code);
  2903.               bcopy (x, new_x, (sizeof (*new_x) - sizeof (new_x->fld)
  2904.                     + (sizeof (new_x->fld[0])
  2905.                        * GET_RTX_LENGTH (code))));
  2906.               x = new_x;
  2907.               copied = 1;
  2908.             }
  2909.           XVEC (x, i) = new_v;
  2910.           copied_vec = 1;
  2911.         }
  2912.           XVECEXP (x, i, j) = new;
  2913.         }
  2914.     }
  2915.     }
  2916.  
  2917.   return x;
  2918. }
  2919.  
  2920. /* Scan INSN and eliminate all eliminable registers in it.
  2921.  
  2922.    If REPLACE is nonzero, do the replacement destructively.  Also
  2923.    delete the insn as dead it if it is setting an eliminable register.
  2924.  
  2925.    If REPLACE is zero, do all our allocations in reload_obstack.
  2926.  
  2927.    If no eliminations were done and this insn doesn't require any elimination
  2928.    processing (these are not identical conditions: it might be updating sp,
  2929.    but not referencing fp; this needs to be seen during reload_as_needed so
  2930.    that the offset between fp and sp can be taken into consideration), zero
  2931.    is returned.  Otherwise, 1 is returned.  */
  2932.  
  2933. static int
  2934. eliminate_regs_in_insn (insn, replace)
  2935.      rtx insn;
  2936.      int replace;
  2937. {
  2938.   rtx old_body = PATTERN (insn);
  2939.   rtx new_body;
  2940.   int val = 0;
  2941.   struct elim_table *ep;
  2942.  
  2943.   if (! replace)
  2944.     push_obstacks (&reload_obstack, &reload_obstack);
  2945.  
  2946.   if (GET_CODE (old_body) == SET && GET_CODE (SET_DEST (old_body)) == REG
  2947.       && REGNO (SET_DEST (old_body)) < FIRST_PSEUDO_REGISTER)
  2948.     {
  2949.       /* Check for setting an eliminable register.  */
  2950.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2951.     if (ep->from_rtx == SET_DEST (old_body) && ep->can_eliminate)
  2952.       {
  2953.         /* In this case this insn isn't serving a useful purpose.  We
  2954.            will delete it in reload_as_needed once we know that this
  2955.            elimination is, in fact, being done.
  2956.  
  2957.            If REPLACE isn't set, we can't delete this insn, but neededn't
  2958.            process it since it won't be used unless something changes.  */
  2959.         if (replace)
  2960.           delete_dead_insn (insn);
  2961.         val = 1;
  2962.         goto done;
  2963.       }
  2964.  
  2965.       /* Check for (set (reg) (plus (reg from) (offset))) where the offset
  2966.      in the insn is the negative of the offset in FROM.  Substitute
  2967.      (set (reg) (reg to)) for the insn and change its code.
  2968.  
  2969.      We have to do this here, rather than in eliminate_regs, do that we can
  2970.      change the insn code.  */
  2971.  
  2972.       if (GET_CODE (SET_SRC (old_body)) == PLUS
  2973.       && GET_CODE (XEXP (SET_SRC (old_body), 0)) == REG
  2974.       && GET_CODE (XEXP (SET_SRC (old_body), 1)) == CONST_INT)
  2975.     for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2976.          ep++)
  2977.       if (ep->from_rtx == XEXP (SET_SRC (old_body), 0)
  2978.           && ep->can_eliminate
  2979.           && ep->offset == - INTVAL (XEXP (SET_SRC (old_body), 1)))
  2980.         {
  2981.           PATTERN (insn) = gen_rtx (SET, VOIDmode,
  2982.                     SET_DEST (old_body), ep->to_rtx);
  2983.           INSN_CODE (insn) = -1;
  2984.           val = 1;
  2985.           goto done;
  2986.         }
  2987.     }
  2988.  
  2989.   old_asm_operands_vec = 0;
  2990.  
  2991.   /* Replace the body of this insn with a substituted form.  If we changed
  2992.      something, return non-zero.  If this is the final call for this
  2993.      insn (REPLACE is non-zero), do the elimination in REG_NOTES as well.
  2994.  
  2995.      If we are replacing a body that was a (set X (plus Y Z)), try to
  2996.      re-recognize the insn.  We do this in case we had a simple addition
  2997.      but now can do this as a load-address.  This saves an insn in this
  2998.      common case. */
  2999.  
  3000.   new_body = eliminate_regs (old_body, 0, replace ? insn : NULL_RTX);
  3001.   if (new_body != old_body)
  3002.     {
  3003.       /* If we aren't replacing things permanently and we changed something,
  3004.      make another copy to ensure that all the RTL is new.  Otherwise
  3005.      things can go wrong if find_reload swaps commutative operands
  3006.      and one is inside RTL that has been copied while the other is not. */
  3007.  
  3008.       /* Don't copy an asm_operands because (1) there's no need and (2)
  3009.      copy_rtx can't do it properly when there are multiple outputs.  */
  3010.       if (! replace && asm_noperands (old_body) < 0)
  3011.     new_body = copy_rtx (new_body);
  3012.  
  3013.       /* If we had a move insn but now we don't, rerecognize it.  */
  3014.       if ((GET_CODE (old_body) == SET && GET_CODE (SET_SRC (old_body)) == REG
  3015.        && (GET_CODE (new_body) != SET
  3016.            || GET_CODE (SET_SRC (new_body)) != REG))
  3017.       /* If this was an add insn before, rerecognize.  */
  3018.       ||
  3019.       (GET_CODE (old_body) == SET
  3020.        && GET_CODE (SET_SRC (old_body)) == PLUS))
  3021.     {
  3022.       if (! validate_change (insn, &PATTERN (insn), new_body, 0))
  3023.         /* If recognition fails, store the new body anyway.
  3024.            It's normal to have recognition failures here
  3025.            due to bizarre memory addresses; reloading will fix them.  */
  3026.         PATTERN (insn) = new_body;
  3027.     }
  3028.       else
  3029.     PATTERN (insn) = new_body;
  3030.  
  3031.       if (replace && REG_NOTES (insn))
  3032.     REG_NOTES (insn) = eliminate_regs (REG_NOTES (insn), 0, NULL_RTX);
  3033.       val = 1;
  3034.     }
  3035.  
  3036.   /* Loop through all elimination pairs.  See if any have changed and
  3037.      recalculate the number not at initial offset.
  3038.  
  3039.      Compute the maximum offset (minimum offset if the stack does not
  3040.      grow downward) for each elimination pair.
  3041.  
  3042.      We also detect a cases where register elimination cannot be done,
  3043.      namely, if a register would be both changed and referenced outside a MEM
  3044.      in the resulting insn since such an insn is often undefined and, even if
  3045.      not, we cannot know what meaning will be given to it.  Note that it is
  3046.      valid to have a register used in an address in an insn that changes it
  3047.      (presumably with a pre- or post-increment or decrement).
  3048.  
  3049.      If anything changes, return nonzero.  */
  3050.  
  3051.   num_not_at_initial_offset = 0;
  3052.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  3053.     {
  3054.       if (ep->previous_offset != ep->offset && ep->ref_outside_mem)
  3055.     ep->can_eliminate = 0;
  3056.  
  3057.       ep->ref_outside_mem = 0;
  3058.  
  3059.       if (ep->previous_offset != ep->offset)
  3060.     val = 1;
  3061.  
  3062.       ep->previous_offset = ep->offset;
  3063.       if (ep->can_eliminate && ep->offset != ep->initial_offset)
  3064.     num_not_at_initial_offset++;
  3065.  
  3066. #ifdef STACK_GROWS_DOWNWARD
  3067.       ep->max_offset = MAX (ep->max_offset, ep->offset);
  3068. #else
  3069.       ep->max_offset = MIN (ep->max_offset, ep->offset);
  3070. #endif
  3071.     }
  3072.  
  3073.  done:
  3074.   if (! replace)
  3075.     pop_obstacks ();
  3076.  
  3077.   return val;
  3078. }
  3079.  
  3080. /* Given X, a SET or CLOBBER of DEST, if DEST is the target of a register
  3081.    replacement we currently believe is valid, mark it as not eliminable if X
  3082.    modifies DEST in any way other than by adding a constant integer to it.
  3083.  
  3084.    If DEST is the frame pointer, we do nothing because we assume that
  3085.    all assignments to the frame pointer are nonlocal gotos and are being done
  3086.    at a time when they are valid and do not disturb anything else.
  3087.    Some machines want to eliminate a fake argument pointer with either the
  3088.    frame or stack pointer.  Assignments to the frame pointer must not prevent
  3089.    this elimination.
  3090.  
  3091.    Called via note_stores from reload before starting its passes to scan
  3092.    the insns of the function.  */
  3093.  
  3094. static void
  3095. mark_not_eliminable (dest, x)
  3096.      rtx dest;
  3097.      rtx x;
  3098. {
  3099.   register int i;
  3100.  
  3101.   /* A SUBREG of a hard register here is just changing its mode.  We should
  3102.      not see a SUBREG of an eliminable hard register, but check just in
  3103.      case.  */
  3104.   if (GET_CODE (dest) == SUBREG)
  3105.     dest = SUBREG_REG (dest);
  3106.  
  3107.   if (dest == frame_pointer_rtx)
  3108.     return;
  3109.  
  3110.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  3111.     if (reg_eliminate[i].can_eliminate && dest == reg_eliminate[i].to_rtx
  3112.     && (GET_CODE (x) != SET
  3113.         || GET_CODE (SET_SRC (x)) != PLUS
  3114.         || XEXP (SET_SRC (x), 0) != dest
  3115.         || GET_CODE (XEXP (SET_SRC (x), 1)) != CONST_INT))
  3116.       {
  3117.     reg_eliminate[i].can_eliminate_previous
  3118.       = reg_eliminate[i].can_eliminate = 0;
  3119.     num_eliminable--;
  3120.       }
  3121. }
  3122.  
  3123. /* Kick all pseudos out of hard register REGNO.
  3124.    If GLOBAL is nonzero, try to find someplace else to put them.
  3125.    If DUMPFILE is nonzero, log actions taken on that file.
  3126.  
  3127.    If CANT_ELIMINATE is nonzero, it means that we are doing this spill
  3128.    because we found we can't eliminate some register.  In the case, no pseudos
  3129.    are allowed to be in the register, even if they are only in a block that
  3130.    doesn't require spill registers, unlike the case when we are spilling this
  3131.    hard reg to produce another spill register.
  3132.  
  3133.    Return nonzero if any pseudos needed to be kicked out.  */
  3134.  
  3135. static int
  3136. spill_hard_reg (regno, global, dumpfile, cant_eliminate)
  3137.      register int regno;
  3138.      int global;
  3139.      FILE *dumpfile;
  3140.      int cant_eliminate;
  3141. {
  3142.   int something_changed = 0;
  3143.   register int i;
  3144.  
  3145.   SET_HARD_REG_BIT (forbidden_regs, regno);
  3146.  
  3147.   /* Spill every pseudo reg that was allocated to this reg
  3148.      or to something that overlaps this reg.  */
  3149.  
  3150.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  3151.     if (reg_renumber[i] >= 0
  3152.     && reg_renumber[i] <= regno
  3153.     && (reg_renumber[i]
  3154.         + HARD_REGNO_NREGS (reg_renumber[i],
  3155.                 PSEUDO_REGNO_MODE (i))
  3156.         > regno))
  3157.       {
  3158.     enum reg_class class = REGNO_REG_CLASS (regno);
  3159.  
  3160.     /* If this register belongs solely to a basic block which needed no
  3161.        spilling of any class that this register is contained in,
  3162.        leave it be, unless we are spilling this register because
  3163.        it was a hard register that can't be eliminated.   */
  3164.  
  3165.     if (! cant_eliminate
  3166.         && basic_block_needs[0]
  3167.         && reg_basic_block[i] >= 0
  3168.         && basic_block_needs[(int) class][reg_basic_block[i]] == 0)
  3169.       {
  3170.         enum reg_class *p;
  3171.  
  3172.         for (p = reg_class_superclasses[(int) class];
  3173.          *p != LIM_REG_CLASSES; p++)
  3174.           if (basic_block_needs[(int) *p][reg_basic_block[i]] > 0)
  3175.         break;
  3176.  
  3177.         if (*p == LIM_REG_CLASSES)
  3178.           continue;
  3179.       }
  3180.  
  3181.     /* Mark it as no longer having a hard register home.  */
  3182.     reg_renumber[i] = -1;
  3183.     /* We will need to scan everything again.  */
  3184.     something_changed = 1;
  3185.     if (global)
  3186.         retry_global_alloc (i, forbidden_regs);
  3187.  
  3188.     alter_reg (i, regno);
  3189.     if (dumpfile)
  3190.       {
  3191.         if (reg_renumber[i] == -1)
  3192.           fprintf (dumpfile, " Register %d now on stack.\n\n", i);
  3193.         else
  3194.           fprintf (dumpfile, " Register %d now in %d.\n\n",
  3195.                i, reg_renumber[i]);
  3196.       }
  3197.       }
  3198.  
  3199.   return something_changed;
  3200. }
  3201.  
  3202. /* Find all paradoxical subregs within X and update reg_max_ref_width.  */
  3203.  
  3204. static void
  3205. scan_paradoxical_subregs (x)
  3206.      register rtx x;
  3207. {
  3208.   register int i;
  3209.   register char *fmt;
  3210.   register enum rtx_code code = GET_CODE (x);
  3211.  
  3212.   switch (code)
  3213.     {
  3214.     case CONST_INT:
  3215.     case CONST:
  3216.     case SYMBOL_REF:
  3217.     case LABEL_REF:
  3218.     case CONST_DOUBLE:
  3219.     case CC0:
  3220.     case PC:
  3221.     case REG:
  3222.     case USE:
  3223.     case CLOBBER:
  3224.       return;
  3225.  
  3226.     case SUBREG:
  3227.       if (GET_CODE (SUBREG_REG (x)) == REG
  3228.       && GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  3229.     reg_max_ref_width[REGNO (SUBREG_REG (x))]
  3230.       = GET_MODE_SIZE (GET_MODE (x));
  3231.       return;
  3232.     }
  3233.  
  3234.   fmt = GET_RTX_FORMAT (code);
  3235.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3236.     {
  3237.       if (fmt[i] == 'e')
  3238.     scan_paradoxical_subregs (XEXP (x, i));
  3239.       else if (fmt[i] == 'E')
  3240.     {
  3241.       register int j;
  3242.       for (j = XVECLEN (x, i) - 1; j >=0; j--)
  3243.         scan_paradoxical_subregs (XVECEXP (x, i, j));
  3244.     }
  3245.     }
  3246. }
  3247.  
  3248. struct hard_reg_n_uses { int regno; int uses; };
  3249.  
  3250. static int
  3251. hard_reg_use_compare (p1, p2)
  3252.      struct hard_reg_n_uses *p1, *p2;
  3253. {
  3254.   int tem = p1->uses - p2->uses;
  3255.   if (tem != 0) return tem;
  3256.   /* If regs are equally good, sort by regno,
  3257.      so that the results of qsort leave nothing to chance.  */
  3258.   return p1->regno - p2->regno;
  3259. }
  3260.  
  3261. /* Choose the order to consider regs for use as reload registers
  3262.    based on how much trouble would be caused by spilling one.
  3263.    Store them in order of decreasing preference in potential_reload_regs.  */
  3264.  
  3265. static void
  3266. order_regs_for_reload ()
  3267. {
  3268.   register int i;
  3269.   register int o = 0;
  3270.   int large = 0;
  3271.  
  3272.   struct hard_reg_n_uses hard_reg_n_uses[FIRST_PSEUDO_REGISTER];
  3273.  
  3274.   CLEAR_HARD_REG_SET (bad_spill_regs);
  3275.  
  3276.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3277.     potential_reload_regs[i] = -1;
  3278.  
  3279.   /* Count number of uses of each hard reg by pseudo regs allocated to it
  3280.      and then order them by decreasing use.  */
  3281.  
  3282.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3283.     {
  3284.       hard_reg_n_uses[i].uses = 0;
  3285.       hard_reg_n_uses[i].regno = i;
  3286.     }
  3287.  
  3288.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  3289.     {
  3290.       int regno = reg_renumber[i];
  3291.       if (regno >= 0)
  3292.     {
  3293.       int lim = regno + HARD_REGNO_NREGS (regno, PSEUDO_REGNO_MODE (i));
  3294.       while (regno < lim)
  3295.         hard_reg_n_uses[regno++].uses += reg_n_refs[i];
  3296.     }
  3297.       large += reg_n_refs[i];
  3298.     }
  3299.  
  3300.   /* Now fixed registers (which cannot safely be used for reloading)
  3301.      get a very high use count so they will be considered least desirable.
  3302.      Registers used explicitly in the rtl code are almost as bad.  */
  3303.  
  3304.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3305.     {
  3306.       if (fixed_regs[i])
  3307.     {
  3308.       hard_reg_n_uses[i].uses += 2 * large + 2;
  3309.       SET_HARD_REG_BIT (bad_spill_regs, i);
  3310.     }
  3311.       else if (regs_explicitly_used[i])
  3312.     {
  3313.       hard_reg_n_uses[i].uses += large + 1;
  3314.       /* ??? We are doing this here because of the potential that
  3315.          bad code may be generated if a register explicitly used in
  3316.          an insn was used as a spill register for that insn.  But
  3317.          not using these are spill registers may lose on some machine.
  3318.          We'll have to see how this works out.  */
  3319.       SET_HARD_REG_BIT (bad_spill_regs, i);
  3320.     }
  3321.     }
  3322.   hard_reg_n_uses[FRAME_POINTER_REGNUM].uses += 2 * large + 2;
  3323.   SET_HARD_REG_BIT (bad_spill_regs, FRAME_POINTER_REGNUM);
  3324.  
  3325. #ifdef ELIMINABLE_REGS
  3326.   /* If registers other than the frame pointer are eliminable, mark them as
  3327.      poor choices.  */
  3328.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  3329.     {
  3330.       hard_reg_n_uses[reg_eliminate[i].from].uses += 2 * large + 2;
  3331.       SET_HARD_REG_BIT (bad_spill_regs, reg_eliminate[i].from);
  3332.     }
  3333. #endif
  3334.  
  3335.   /* Prefer registers not so far used, for use in temporary loading.
  3336.      Among them, if REG_ALLOC_ORDER is defined, use that order.
  3337.      Otherwise, prefer registers not preserved by calls.  */
  3338.  
  3339. #ifdef REG_ALLOC_ORDER
  3340.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3341.     {
  3342.       int regno = reg_alloc_order[i];
  3343.  
  3344.       if (hard_reg_n_uses[regno].uses == 0)
  3345.     potential_reload_regs[o++] = regno;
  3346.     }
  3347. #else
  3348.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3349.     {
  3350.       if (hard_reg_n_uses[i].uses == 0 && call_used_regs[i])
  3351.     potential_reload_regs[o++] = i;
  3352.     }
  3353.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3354.     {
  3355.       if (hard_reg_n_uses[i].uses == 0 && ! call_used_regs[i])
  3356.     potential_reload_regs[o++] = i;
  3357.     }
  3358. #endif
  3359.  
  3360.   qsort (hard_reg_n_uses, FIRST_PSEUDO_REGISTER,
  3361.      sizeof hard_reg_n_uses[0], hard_reg_use_compare);
  3362.  
  3363.   /* Now add the regs that are already used,
  3364.      preferring those used less often.  The fixed and otherwise forbidden
  3365.      registers will be at the end of this list.  */
  3366.  
  3367.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3368.     if (hard_reg_n_uses[i].uses != 0)
  3369.       potential_reload_regs[o++] = hard_reg_n_uses[i].regno;
  3370. }
  3371.  
  3372. /* Reload pseudo-registers into hard regs around each insn as needed.
  3373.    Additional register load insns are output before the insn that needs it
  3374.    and perhaps store insns after insns that modify the reloaded pseudo reg.
  3375.  
  3376.    reg_last_reload_reg and reg_reloaded_contents keep track of
  3377.    which pseudo-registers are already available in reload registers.
  3378.    We update these for the reloads that we perform,
  3379.    as the insns are scanned.  */
  3380.  
  3381. static void
  3382. reload_as_needed (first, live_known)
  3383.      rtx first;
  3384.      int live_known;
  3385. {
  3386.   register rtx insn;
  3387.   register int i;
  3388.   int this_block = 0;
  3389.   rtx x;
  3390.   rtx after_call = 0;
  3391.  
  3392.   bzero (spill_reg_rtx, sizeof spill_reg_rtx);
  3393.   reg_last_reload_reg = (rtx *) alloca (max_regno * sizeof (rtx));
  3394.   bzero (reg_last_reload_reg, max_regno * sizeof (rtx));
  3395.   reg_has_output_reload = (char *) alloca (max_regno);
  3396.   for (i = 0; i < n_spills; i++)
  3397.     {
  3398.       reg_reloaded_contents[i] = -1;
  3399.       reg_reloaded_insn[i] = 0;
  3400.     }
  3401.  
  3402.   /* Reset all offsets on eliminable registers to their initial values.  */
  3403. #ifdef ELIMINABLE_REGS
  3404.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  3405.     {
  3406.       INITIAL_ELIMINATION_OFFSET (reg_eliminate[i].from, reg_eliminate[i].to,
  3407.                   reg_eliminate[i].initial_offset);
  3408.       reg_eliminate[i].previous_offset
  3409.     = reg_eliminate[i].offset = reg_eliminate[i].initial_offset;
  3410.     }
  3411. #else
  3412.   INITIAL_FRAME_POINTER_OFFSET (reg_eliminate[0].initial_offset);
  3413.   reg_eliminate[0].previous_offset
  3414.     = reg_eliminate[0].offset = reg_eliminate[0].initial_offset;
  3415. #endif
  3416.  
  3417.   num_not_at_initial_offset = 0;
  3418.  
  3419.   for (insn = first; insn;)
  3420.     {
  3421.       register rtx next = NEXT_INSN (insn);
  3422.  
  3423.       /* Notice when we move to a new basic block.  */
  3424.       if (live_known && this_block + 1 < n_basic_blocks
  3425.       && insn == basic_block_head[this_block+1])
  3426.     ++this_block;
  3427.  
  3428.       /* If we pass a label, copy the offsets from the label information
  3429.      into the current offsets of each elimination.  */
  3430.       if (GET_CODE (insn) == CODE_LABEL)
  3431.     {
  3432.       num_not_at_initial_offset = 0;
  3433.       for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  3434.         {
  3435.           reg_eliminate[i].offset = reg_eliminate[i].previous_offset
  3436.         = offsets_at[CODE_LABEL_NUMBER (insn)][i];
  3437.           if (reg_eliminate[i].can_eliminate
  3438.           && (reg_eliminate[i].offset
  3439.               != reg_eliminate[i].initial_offset))
  3440.         num_not_at_initial_offset++;
  3441.         }
  3442.     }
  3443.  
  3444.       else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  3445.     {
  3446.       rtx avoid_return_reg = 0;
  3447.  
  3448. #ifdef SMALL_REGISTER_CLASSES
  3449.       /* Set avoid_return_reg if this is an insn
  3450.          that might use the value of a function call.  */
  3451.       if (GET_CODE (insn) == CALL_INSN)
  3452.         {
  3453.           if (GET_CODE (PATTERN (insn)) == SET)
  3454.         after_call = SET_DEST (PATTERN (insn));
  3455.           else if (GET_CODE (PATTERN (insn)) == PARALLEL
  3456.                && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  3457.         after_call = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
  3458.           else
  3459.         after_call = 0;
  3460.         }
  3461.       else if (after_call != 0
  3462.            && !(GET_CODE (PATTERN (insn)) == SET
  3463.             && SET_DEST (PATTERN (insn)) == stack_pointer_rtx))
  3464.         {
  3465.           if (reg_mentioned_p (after_call, PATTERN (insn)))
  3466.         avoid_return_reg = after_call;
  3467.           after_call = 0;
  3468.         }
  3469. #endif /* SMALL_REGISTER_CLASSES */
  3470.  
  3471.       /* If this is a USE and CLOBBER of a MEM, ensure that any
  3472.          references to eliminable registers have been removed.  */
  3473.  
  3474.       if ((GET_CODE (PATTERN (insn)) == USE
  3475.            || GET_CODE (PATTERN (insn)) == CLOBBER)
  3476.           && GET_CODE (XEXP (PATTERN (insn), 0)) == MEM)
  3477.         XEXP (XEXP (PATTERN (insn), 0), 0)
  3478.           = eliminate_regs (XEXP (XEXP (PATTERN (insn), 0), 0),
  3479.                 GET_MODE (XEXP (PATTERN (insn), 0)), NULL_RTX);
  3480.  
  3481.       /* If we need to do register elimination processing, do so.
  3482.          This might delete the insn, in which case we are done.  */
  3483.       if (num_eliminable && GET_MODE (insn) == QImode)
  3484.         {
  3485.           eliminate_regs_in_insn (insn, 1);
  3486.           if (GET_CODE (insn) == NOTE)
  3487.         {
  3488.           insn = next;
  3489.           continue;
  3490.         }
  3491.         }
  3492.       if (GET_MODE (insn) == VOIDmode)
  3493.         n_reloads = 0;
  3494.       /* First find the pseudo regs that must be reloaded for this insn.
  3495.          This info is returned in the tables reload_... (see reload.h).
  3496.          Also modify the body of INSN by substituting RELOAD
  3497.          rtx's for those pseudo regs.  */
  3498.       else
  3499.         {
  3500.           bzero (reg_has_output_reload, max_regno);
  3501.           CLEAR_HARD_REG_SET (reg_is_output_reload);
  3502.  
  3503.           find_reloads (insn, 1, spill_indirect_levels, live_known,
  3504.                 spill_reg_order);
  3505.         }
  3506.  
  3507.       if (n_reloads > 0)
  3508.         {
  3509.           rtx prev = PREV_INSN (insn), next = NEXT_INSN (insn);
  3510.           rtx p;
  3511.           int class;
  3512.  
  3513.           /* If this block has not had spilling done for a
  3514.          particular class, deactivate any optional reloads
  3515.          of that class lest they try to use a spill-reg which isn't
  3516.          available here.  If we have any non-optionals that need a
  3517.          spill reg, abort.  */
  3518.  
  3519.           for (class = 0; class < N_REG_CLASSES; class++)
  3520.         if (basic_block_needs[class] != 0
  3521.             && basic_block_needs[class][this_block] == 0)
  3522.           for (i = 0; i < n_reloads; i++)
  3523.             if (class == (int) reload_reg_class[i])
  3524.               {
  3525.             if (reload_optional[i])
  3526.               {
  3527.                 reload_in[i] = reload_out[i] = 0;
  3528.                 reload_secondary_p[i] = 0;
  3529.               }
  3530.             else if (reload_reg_rtx[i] == 0
  3531.                  && (reload_in[i] != 0 || reload_out[i] != 0
  3532.                      || reload_secondary_p[i] != 0))
  3533.               abort ();
  3534.               }
  3535.  
  3536.           /* Now compute which reload regs to reload them into.  Perhaps
  3537.          reusing reload regs from previous insns, or else output
  3538.          load insns to reload them.  Maybe output store insns too.
  3539.          Record the choices of reload reg in reload_reg_rtx.  */
  3540.           choose_reload_regs (insn, avoid_return_reg);
  3541.  
  3542.           /* Generate the insns to reload operands into or out of
  3543.          their reload regs.  */
  3544.           emit_reload_insns (insn);
  3545.  
  3546.           /* Substitute the chosen reload regs from reload_reg_rtx
  3547.          into the insn's body (or perhaps into the bodies of other
  3548.          load and store insn that we just made for reloading
  3549.          and that we moved the structure into).  */
  3550.           subst_reloads ();
  3551.  
  3552.           /* If this was an ASM, make sure that all the reload insns
  3553.          we have generated are valid.  If not, give an error
  3554.          and delete them.  */
  3555.  
  3556.           if (asm_noperands (PATTERN (insn)) >= 0)
  3557.         for (p = NEXT_INSN (prev); p != next; p = NEXT_INSN (p))
  3558.           if (p != insn && GET_RTX_CLASS (GET_CODE (p)) == 'i'
  3559.               && (recog_memoized (p) < 0
  3560.               || (insn_extract (p),
  3561.                   ! constrain_operands (INSN_CODE (p), 1))))
  3562.             {
  3563.               error_for_asm (insn,
  3564.                      "`asm' operand requires impossible reload");
  3565.               PUT_CODE (p, NOTE);
  3566.               NOTE_SOURCE_FILE (p) = 0;
  3567.               NOTE_LINE_NUMBER (p) = NOTE_INSN_DELETED;
  3568.             }
  3569.         }
  3570.       /* Any previously reloaded spilled pseudo reg, stored in this insn,
  3571.          is no longer validly lying around to save a future reload.
  3572.          Note that this does not detect pseudos that were reloaded
  3573.          for this insn in order to be stored in
  3574.          (obeying register constraints).  That is correct; such reload
  3575.          registers ARE still valid.  */
  3576.       note_stores (PATTERN (insn), forget_old_reloads_1);
  3577.  
  3578.       /* There may have been CLOBBER insns placed after INSN.  So scan
  3579.          between INSN and NEXT and use them to forget old reloads.  */
  3580.       for (x = NEXT_INSN (insn); x != next; x = NEXT_INSN (x))
  3581.         if (GET_CODE (x) == INSN && GET_CODE (PATTERN (x)) == CLOBBER)
  3582.           note_stores (PATTERN (x), forget_old_reloads_1);
  3583.  
  3584. #ifdef AUTO_INC_DEC
  3585.       /* Likewise for regs altered by auto-increment in this insn.
  3586.          But note that the reg-notes are not changed by reloading:
  3587.          they still contain the pseudo-regs, not the spill regs.  */
  3588.       for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
  3589.         if (REG_NOTE_KIND (x) == REG_INC)
  3590.           {
  3591.         /* See if this pseudo reg was reloaded in this insn.
  3592.            If so, its last-reload info is still valid
  3593.            because it is based on this insn's reload.  */
  3594.         for (i = 0; i < n_reloads; i++)
  3595.           if (reload_out[i] == XEXP (x, 0))
  3596.             break;
  3597.  
  3598.         if (i != n_reloads)
  3599.           forget_old_reloads_1 (XEXP (x, 0));
  3600.           }
  3601. #endif
  3602.     }
  3603.       /* A reload reg's contents are unknown after a label.  */
  3604.       if (GET_CODE (insn) == CODE_LABEL)
  3605.     for (i = 0; i < n_spills; i++)
  3606.       {
  3607.         reg_reloaded_contents[i] = -1;
  3608.         reg_reloaded_insn[i] = 0;
  3609.       }
  3610.  
  3611.       /* Don't assume a reload reg is still good after a call insn
  3612.      if it is a call-used reg.  */
  3613.       if (GET_CODE (insn) == CODE_LABEL || GET_CODE (insn) == CALL_INSN)
  3614.     for (i = 0; i < n_spills; i++)
  3615.       if (call_used_regs[spill_regs[i]])
  3616.         {
  3617.           reg_reloaded_contents[i] = -1;
  3618.           reg_reloaded_insn[i] = 0;
  3619.         }
  3620.  
  3621.       /* In case registers overlap, allow certain insns to invalidate
  3622.      particular hard registers.  */
  3623.  
  3624. #ifdef INSN_CLOBBERS_REGNO_P
  3625.       for (i = 0 ; i < n_spills ; i++)
  3626.     if (INSN_CLOBBERS_REGNO_P (insn, spill_regs[i]))
  3627.       {
  3628.         reg_reloaded_contents[i] = -1;
  3629.         reg_reloaded_insn[i] = 0;
  3630.       }
  3631. #endif
  3632.  
  3633.       insn = next;
  3634.  
  3635. #ifdef USE_C_ALLOCA
  3636.       alloca (0);
  3637. #endif
  3638.     }
  3639. }
  3640.  
  3641. /* Discard all record of any value reloaded from X,
  3642.    or reloaded in X from someplace else;
  3643.    unless X is an output reload reg of the current insn.
  3644.  
  3645.    X may be a hard reg (the reload reg)
  3646.    or it may be a pseudo reg that was reloaded from.  */
  3647.  
  3648. static void
  3649. forget_old_reloads_1 (x)
  3650.      rtx x;
  3651. {
  3652.   register int regno;
  3653.   int nr;
  3654.   int offset = 0;
  3655.  
  3656.   /* note_stores does give us subregs of hard regs.  */
  3657.   while (GET_CODE (x) == SUBREG)
  3658.     {
  3659.       offset += SUBREG_WORD (x);
  3660.       x = SUBREG_REG (x);
  3661.     }
  3662.  
  3663.   if (GET_CODE (x) != REG)
  3664.     return;
  3665.  
  3666.   regno = REGNO (x) + offset;
  3667.  
  3668.   if (regno >= FIRST_PSEUDO_REGISTER)
  3669.     nr = 1;
  3670.   else
  3671.     {
  3672.       int i;
  3673.       nr = HARD_REGNO_NREGS (regno, GET_MODE (x));
  3674.       /* Storing into a spilled-reg invalidates its contents.
  3675.      This can happen if a block-local pseudo is allocated to that reg
  3676.      and it wasn't spilled because this block's total need is 0.
  3677.      Then some insn might have an optional reload and use this reg.  */
  3678.       for (i = 0; i < nr; i++)
  3679.     if (spill_reg_order[regno + i] >= 0
  3680.         /* But don't do this if the reg actually serves as an output
  3681.            reload reg in the current instruction.  */
  3682.         && (n_reloads == 0
  3683.         || ! TEST_HARD_REG_BIT (reg_is_output_reload, regno + i)))
  3684.       {
  3685.         reg_reloaded_contents[spill_reg_order[regno + i]] = -1;
  3686.         reg_reloaded_insn[spill_reg_order[regno + i]] = 0;
  3687.       }
  3688.     }
  3689.  
  3690.   /* Since value of X has changed,
  3691.      forget any value previously copied from it.  */
  3692.  
  3693.   while (nr-- > 0)
  3694.     /* But don't forget a copy if this is the output reload
  3695.        that establishes the copy's validity.  */
  3696.     if (n_reloads == 0 || reg_has_output_reload[regno + nr] == 0)
  3697.       reg_last_reload_reg[regno + nr] = 0;
  3698. }
  3699.  
  3700. /* For each reload, the mode of the reload register.  */
  3701. static enum machine_mode reload_mode[MAX_RELOADS];
  3702.  
  3703. /* For each reload, the largest number of registers it will require.  */
  3704. static int reload_nregs[MAX_RELOADS];
  3705.  
  3706. /* Comparison function for qsort to decide which of two reloads
  3707.    should be handled first.  *P1 and *P2 are the reload numbers.  */
  3708.  
  3709. static int
  3710. reload_reg_class_lower (p1, p2)
  3711.      short *p1, *p2;
  3712. {
  3713.   register int r1 = *p1, r2 = *p2;
  3714.   register int t;
  3715.  
  3716.   /* Consider required reloads before optional ones.  */
  3717.   t = reload_optional[r1] - reload_optional[r2];
  3718.   if (t != 0)
  3719.     return t;
  3720.  
  3721.   /* Count all solitary classes before non-solitary ones.  */
  3722.   t = ((reg_class_size[(int) reload_reg_class[r2]] == 1)
  3723.        - (reg_class_size[(int) reload_reg_class[r1]] == 1));
  3724.   if (t != 0)
  3725.     return t;
  3726.  
  3727.   /* Aside from solitaires, consider all multi-reg groups first.  */
  3728.   t = reload_nregs[r2] - reload_nregs[r1];
  3729.   if (t != 0)
  3730.     return t;
  3731.  
  3732.   /* Consider reloads in order of increasing reg-class number.  */
  3733.   t = (int) reload_reg_class[r1] - (int) reload_reg_class[r2];
  3734.   if (t != 0)
  3735.     return t;
  3736.  
  3737.   /* If reloads are equally urgent, sort by reload number,
  3738.      so that the results of qsort leave nothing to chance.  */
  3739.   return r1 - r2;
  3740. }
  3741.  
  3742. /* The following HARD_REG_SETs indicate when each hard register is
  3743.    used for a reload of various parts of the current insn.  */
  3744.  
  3745. /* If reg is in use as a reload reg for a RELOAD_OTHER reload.  */
  3746. static HARD_REG_SET reload_reg_used;
  3747. /* If reg is in use for a RELOAD_FOR_INPUT_RELOAD_ADDRESS reload.  */
  3748. static HARD_REG_SET reload_reg_used_in_input_addr;
  3749. /* If reg is in use for a RELOAD_FOR_OUTPUT_RELOAD_ADDRESS reload.  */
  3750. static HARD_REG_SET reload_reg_used_in_output_addr;
  3751. /* If reg is in use for a RELOAD_FOR_OPERAND_ADDRESS reload.  */
  3752. static HARD_REG_SET reload_reg_used_in_op_addr;
  3753. /* If reg is in use for a RELOAD_FOR_INPUT reload.  */
  3754. static HARD_REG_SET reload_reg_used_in_input;
  3755. /* If reg is in use for a RELOAD_FOR_OUTPUT reload.  */
  3756. static HARD_REG_SET reload_reg_used_in_output;
  3757.  
  3758. /* If reg is in use as a reload reg for any sort of reload.  */
  3759. static HARD_REG_SET reload_reg_used_at_all;
  3760.  
  3761. /* Mark reg REGNO as in use for a reload of the sort spec'd by WHEN_NEEDED.
  3762.    MODE is used to indicate how many consecutive regs are actually used.  */
  3763.  
  3764. static void
  3765. mark_reload_reg_in_use (regno, when_needed, mode)
  3766.      int regno;
  3767.      enum reload_when_needed when_needed;
  3768.      enum machine_mode mode;
  3769. {
  3770.   int nregs = HARD_REGNO_NREGS (regno, mode);
  3771.   int i;
  3772.  
  3773.   for (i = regno; i < nregs + regno; i++)
  3774.     {
  3775.       switch (when_needed)
  3776.     {
  3777.     case RELOAD_OTHER:
  3778.       SET_HARD_REG_BIT (reload_reg_used, i);
  3779.       break;
  3780.  
  3781.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  3782.       SET_HARD_REG_BIT (reload_reg_used_in_input_addr, i);
  3783.       break;
  3784.  
  3785.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  3786.       SET_HARD_REG_BIT (reload_reg_used_in_output_addr, i);
  3787.       break;
  3788.  
  3789.     case RELOAD_FOR_OPERAND_ADDRESS:
  3790.       SET_HARD_REG_BIT (reload_reg_used_in_op_addr, i);
  3791.       break;
  3792.  
  3793.     case RELOAD_FOR_INPUT:
  3794.       SET_HARD_REG_BIT (reload_reg_used_in_input, i);
  3795.       break;
  3796.  
  3797.     case RELOAD_FOR_OUTPUT:
  3798.       SET_HARD_REG_BIT (reload_reg_used_in_output, i);
  3799.       break;
  3800.     }
  3801.  
  3802.       SET_HARD_REG_BIT (reload_reg_used_at_all, i);
  3803.     }
  3804. }
  3805.  
  3806. /* 1 if reg REGNO is free as a reload reg for a reload of the sort
  3807.    specified by WHEN_NEEDED.  */
  3808.  
  3809. static int
  3810. reload_reg_free_p (regno, when_needed)
  3811.      int regno;
  3812.      enum reload_when_needed when_needed;
  3813. {
  3814.   /* In use for a RELOAD_OTHER means it's not available for anything.  */
  3815.   if (TEST_HARD_REG_BIT (reload_reg_used, regno))
  3816.     return 0;
  3817.   switch (when_needed)
  3818.     {
  3819.     case RELOAD_OTHER:
  3820.       /* In use for anything means not available for a RELOAD_OTHER.  */
  3821.       return ! TEST_HARD_REG_BIT (reload_reg_used_at_all, regno);
  3822.  
  3823.       /* The other kinds of use can sometimes share a register.  */
  3824.     case RELOAD_FOR_INPUT:
  3825.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_input, regno)
  3826.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  3827.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_input_addr, regno));
  3828.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  3829.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_input_addr, regno)
  3830.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_input, regno));
  3831.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  3832.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_output_addr, regno)
  3833.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_output, regno));
  3834.     case RELOAD_FOR_OPERAND_ADDRESS:
  3835.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  3836.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_input, regno)
  3837.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_output, regno));
  3838.     case RELOAD_FOR_OUTPUT:
  3839.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  3840.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_output_addr, regno)
  3841.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_output, regno));
  3842.     }
  3843.   abort ();
  3844. }
  3845.  
  3846. /* Return 1 if the value in reload reg REGNO, as used by a reload
  3847.    needed for the part of the insn specified by WHEN_NEEDED,
  3848.    is not in use for a reload in any prior part of the insn.
  3849.  
  3850.    We can assume that the reload reg was already tested for availability
  3851.    at the time it is needed, and we should not check this again,
  3852.    in case the reg has already been marked in use.  */
  3853.  
  3854. static int
  3855. reload_reg_free_before_p (regno, when_needed)
  3856.      int regno;
  3857.      enum reload_when_needed when_needed;
  3858. {
  3859.   switch (when_needed)
  3860.     {
  3861.     case RELOAD_OTHER:
  3862.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  3863.      its use starts from the beginning, so nothing can use it earlier.  */
  3864.       return 1;
  3865.  
  3866.       /* If this use is for part of the insn,
  3867.      check the reg is not in use for any prior part.  */
  3868.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  3869.       if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno))
  3870.     return 0;
  3871.     case RELOAD_FOR_OUTPUT:
  3872.       if (TEST_HARD_REG_BIT (reload_reg_used_in_input, regno))
  3873.     return 0;
  3874.     case RELOAD_FOR_OPERAND_ADDRESS:
  3875.       if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr, regno))
  3876.     return 0;
  3877.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  3878.     case RELOAD_FOR_INPUT:
  3879.       return 1;
  3880.     }
  3881.   abort ();
  3882. }
  3883.  
  3884. /* Return 1 if the value in reload reg REGNO, as used by a reload
  3885.    needed for the part of the insn specified by WHEN_NEEDED,
  3886.    is still available in REGNO at the end of the insn.
  3887.  
  3888.    We can assume that the reload reg was already tested for availability
  3889.    at the time it is needed, and we should not check this again,
  3890.    in case the reg has already been marked in use.  */
  3891.  
  3892. static int
  3893. reload_reg_reaches_end_p (regno, when_needed)
  3894.      int regno;
  3895.      enum reload_when_needed when_needed;
  3896. {
  3897.   switch (when_needed)
  3898.     {
  3899.     case RELOAD_OTHER:
  3900.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  3901.      its value must reach the end.  */
  3902.       return 1;
  3903.  
  3904.       /* If this use is for part of the insn,
  3905.      its value reaches if no subsequent part uses the same register.  */
  3906.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  3907.     case RELOAD_FOR_INPUT:
  3908.       if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  3909.       || TEST_HARD_REG_BIT (reload_reg_used_in_output, regno))
  3910.     return 0;
  3911.     case RELOAD_FOR_OPERAND_ADDRESS:
  3912.       if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr, regno))
  3913.     return 0;
  3914.     case RELOAD_FOR_OUTPUT:
  3915.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  3916.       return 1;
  3917.     }
  3918.   abort ();
  3919. }
  3920.  
  3921. /* Vector of reload-numbers showing the order in which the reloads should
  3922.    be processed.  */
  3923. short reload_order[MAX_RELOADS];
  3924.  
  3925. /* Indexed by reload number, 1 if incoming value
  3926.    inherited from previous insns.  */
  3927. char reload_inherited[MAX_RELOADS];
  3928.  
  3929. /* For an inherited reload, this is the insn the reload was inherited from,
  3930.    if we know it.  Otherwise, this is 0.  */
  3931. rtx reload_inheritance_insn[MAX_RELOADS];
  3932.  
  3933. /* If non-zero, this is a place to get the value of the reload,
  3934.    rather than using reload_in.  */
  3935. rtx reload_override_in[MAX_RELOADS];
  3936.  
  3937. /* For each reload, the index in spill_regs of the spill register used,
  3938.    or -1 if we did not need one of the spill registers for this reload.  */
  3939. int reload_spill_index[MAX_RELOADS];
  3940.  
  3941. /* Index of last register assigned as a spill register.  We allocate in
  3942.    a round-robin fashio.  */
  3943.  
  3944. static last_spill_reg = 0;
  3945.  
  3946. /* Find a spill register to use as a reload register for reload R.
  3947.    LAST_RELOAD is non-zero if this is the last reload for the insn being
  3948.    processed.
  3949.  
  3950.    Set reload_reg_rtx[R] to the register allocated.
  3951.  
  3952.    If NOERROR is nonzero, we return 1 if successful,
  3953.    or 0 if we couldn't find a spill reg and we didn't change anything.  */
  3954.  
  3955. static int
  3956. allocate_reload_reg (r, insn, last_reload, noerror)
  3957.      int r;
  3958.      rtx insn;
  3959.      int last_reload;
  3960.      int noerror;
  3961. {
  3962.   int i;
  3963.   int pass;
  3964.   int count;
  3965.   rtx new;
  3966.   int regno;
  3967.  
  3968.   /* If we put this reload ahead, thinking it is a group,
  3969.      then insist on finding a group.  Otherwise we can grab a
  3970.      reg that some other reload needs.
  3971.      (That can happen when we have a 68000 DATA_OR_FP_REG
  3972.      which is a group of data regs or one fp reg.)
  3973.      We need not be so restrictive if there are no more reloads
  3974.      for this insn.
  3975.  
  3976.      ??? Really it would be nicer to have smarter handling
  3977.      for that kind of reg class, where a problem like this is normal.
  3978.      Perhaps those classes should be avoided for reloading
  3979.      by use of more alternatives.  */
  3980.  
  3981.   int force_group = reload_nregs[r] > 1 && ! last_reload;
  3982.  
  3983.   /* If we want a single register and haven't yet found one,
  3984.      take any reg in the right class and not in use.
  3985.      If we want a consecutive group, here is where we look for it.
  3986.  
  3987.      We use two passes so we can first look for reload regs to
  3988.      reuse, which are already in use for other reloads in this insn,
  3989.      and only then use additional registers.
  3990.      I think that maximizing reuse is needed to make sure we don't
  3991.      run out of reload regs.  Suppose we have three reloads, and
  3992.      reloads A and B can share regs.  These need two regs.
  3993.      Suppose A and B are given different regs.
  3994.      That leaves none for C.  */
  3995.   for (pass = 0; pass < 2; pass++)
  3996.     {
  3997.       /* I is the index in spill_regs.
  3998.      We advance it round-robin between insns to use all spill regs
  3999.      equally, so that inherited reloads have a chance
  4000.      of leapfrogging each other.  */
  4001.  
  4002.       for (count = 0, i = last_spill_reg; count < n_spills; count++)
  4003.     {
  4004.       int class = (int) reload_reg_class[r];
  4005.  
  4006.       i = (i + 1) % n_spills;
  4007.  
  4008.       if (reload_reg_free_p (spill_regs[i], reload_when_needed[r])
  4009.           && TEST_HARD_REG_BIT (reg_class_contents[class], spill_regs[i])
  4010.           && HARD_REGNO_MODE_OK (spill_regs[i], reload_mode[r])
  4011.           /* Look first for regs to share, then for unshared.  */
  4012.           && (pass || TEST_HARD_REG_BIT (reload_reg_used_at_all,
  4013.                          spill_regs[i])))
  4014.         {
  4015.           int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode[r]);
  4016.           /* Avoid the problem where spilling a GENERAL_OR_FP_REG
  4017.          (on 68000) got us two FP regs.  If NR is 1,
  4018.          we would reject both of them.  */
  4019.           if (force_group)
  4020.         nr = CLASS_MAX_NREGS (reload_reg_class[r], reload_mode[r]);
  4021.           /* If we need only one reg, we have already won.  */
  4022.           if (nr == 1)
  4023.         {
  4024.           /* But reject a single reg if we demand a group.  */
  4025.           if (force_group)
  4026.             continue;
  4027.           break;
  4028.         }
  4029.           /* Otherwise check that as many consecutive regs as we need
  4030.          are available here.
  4031.          Also, don't use for a group registers that are
  4032.          needed for nongroups.  */
  4033.           if (! TEST_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]))
  4034.         while (nr > 1)
  4035.           {
  4036.             regno = spill_regs[i] + nr - 1;
  4037.             if (!(TEST_HARD_REG_BIT (reg_class_contents[class], regno)
  4038.               && spill_reg_order[regno] >= 0
  4039.               && reload_reg_free_p (regno, reload_when_needed[r])
  4040.               && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  4041.                           regno)))
  4042.               break;
  4043.             nr--;
  4044.           }
  4045.           if (nr == 1)
  4046.         break;
  4047.         }
  4048.     }
  4049.  
  4050.       /* If we found something on pass 1, omit pass 2.  */
  4051.       if (count < n_spills)
  4052.     break;
  4053.     }
  4054.  
  4055.   /* We should have found a spill register by now.  */
  4056.   if (count == n_spills)
  4057.     {
  4058.       if (noerror)
  4059.     return 0;
  4060.       goto failure;
  4061.     }
  4062.  
  4063.   last_spill_reg = i;
  4064.  
  4065.   /* Mark as in use for this insn the reload regs we use for this.  */
  4066.   mark_reload_reg_in_use (spill_regs[i], reload_when_needed[r],
  4067.               reload_mode[r]);
  4068.  
  4069.   new = spill_reg_rtx[i];
  4070.  
  4071.   if (new == 0 || GET_MODE (new) != reload_mode[r])
  4072.     spill_reg_rtx[i] = new = gen_rtx (REG, reload_mode[r], spill_regs[i]);
  4073.  
  4074.   reload_reg_rtx[r] = new;
  4075.   reload_spill_index[r] = i;
  4076.   regno = true_regnum (new);
  4077.  
  4078.   /* Detect when the reload reg can't hold the reload mode.
  4079.      This used to be one `if', but Sequent compiler can't handle that.  */
  4080.   if (HARD_REGNO_MODE_OK (regno, reload_mode[r]))
  4081.     {
  4082.       enum machine_mode test_mode = VOIDmode;
  4083.       if (reload_in[r])
  4084.     test_mode = GET_MODE (reload_in[r]);
  4085.       /* If reload_in[r] has VOIDmode, it means we will load it
  4086.      in whatever mode the reload reg has: to wit, reload_mode[r].
  4087.      We have already tested that for validity.  */
  4088.       /* Aside from that, we need to test that the expressions
  4089.      to reload from or into have modes which are valid for this
  4090.      reload register.  Otherwise the reload insns would be invalid.  */
  4091.       if (! (reload_in[r] != 0 && test_mode != VOIDmode
  4092.          && ! HARD_REGNO_MODE_OK (regno, test_mode)))
  4093.     if (! (reload_out[r] != 0
  4094.            && ! HARD_REGNO_MODE_OK (regno, GET_MODE (reload_out[r]))))
  4095.       /* The reg is OK.  */
  4096.       return 1;
  4097.     }
  4098.  
  4099.   /* The reg is not OK.  */
  4100.   if (noerror)
  4101.     return 0;
  4102.  
  4103.  failure:
  4104. #ifdef APPLE_HAX
  4105.       fprintf(stderr, "FILE %s; LINE %d\n", __FILE__, __LINE__);
  4106.       debug_rtx(insn);
  4107. #endif
  4108.   if (asm_noperands (PATTERN (insn)) < 0)
  4109.     /* It's the compiler's fault.  */
  4110.     abort ();
  4111.  
  4112.   /* It's the user's fault; the operand's mode and constraint
  4113.      don't match.  Disable this reload so we don't crash in final.  */
  4114.   error_for_asm (insn,
  4115.          "`asm' operand constraint incompatible with operand size");
  4116.   reload_in[r] = 0;
  4117.   reload_out[r] = 0;
  4118.   reload_reg_rtx[r] = 0;
  4119.   reload_optional[r] = 1;
  4120.   reload_secondary_p[r] = 1;
  4121.  
  4122.   return 1;
  4123. }
  4124.  
  4125. /* Assign hard reg targets for the pseudo-registers we must reload
  4126.    into hard regs for this insn.
  4127.    Also output the instructions to copy them in and out of the hard regs.
  4128.  
  4129.    For machines with register classes, we are responsible for
  4130.    finding a reload reg in the proper class.  */
  4131.  
  4132. static void
  4133. choose_reload_regs (insn, avoid_return_reg)
  4134.      rtx insn;
  4135.      /* This argument is currently ignored.  */
  4136.      rtx avoid_return_reg;
  4137. {
  4138.   register int i, j;
  4139.   int max_group_size = 1;
  4140.   enum reg_class group_class = NO_REGS;
  4141.   int inheritance;
  4142.  
  4143.   rtx save_reload_reg_rtx[MAX_RELOADS];
  4144.   char save_reload_inherited[MAX_RELOADS];
  4145.   rtx save_reload_inheritance_insn[MAX_RELOADS];
  4146.   rtx save_reload_override_in[MAX_RELOADS];
  4147.   int save_reload_spill_index[MAX_RELOADS];
  4148.   HARD_REG_SET save_reload_reg_used;
  4149.   HARD_REG_SET save_reload_reg_used_in_input_addr;
  4150.   HARD_REG_SET save_reload_reg_used_in_output_addr;
  4151.   HARD_REG_SET save_reload_reg_used_in_op_addr;
  4152.   HARD_REG_SET save_reload_reg_used_in_input;
  4153.   HARD_REG_SET save_reload_reg_used_in_output;
  4154.   HARD_REG_SET save_reload_reg_used_at_all;
  4155.  
  4156.   bzero (reload_inherited, MAX_RELOADS);
  4157.   bzero (reload_inheritance_insn, MAX_RELOADS * sizeof (rtx));
  4158.   bzero (reload_override_in, MAX_RELOADS * sizeof (rtx));
  4159.  
  4160.   CLEAR_HARD_REG_SET (reload_reg_used);
  4161.   CLEAR_HARD_REG_SET (reload_reg_used_at_all);
  4162.   CLEAR_HARD_REG_SET (reload_reg_used_in_input_addr);
  4163.   CLEAR_HARD_REG_SET (reload_reg_used_in_output_addr);
  4164.   CLEAR_HARD_REG_SET (reload_reg_used_in_op_addr);
  4165.   CLEAR_HARD_REG_SET (reload_reg_used_in_output);
  4166.   CLEAR_HARD_REG_SET (reload_reg_used_in_input);
  4167.  
  4168.   /* Distinguish output-only and input-only reloads
  4169.      because they can overlap with other things.  */
  4170.   for (j = 0; j < n_reloads; j++)
  4171.     if (reload_when_needed[j] == RELOAD_OTHER
  4172.     && ! reload_needed_for_multiple[j])
  4173.       {
  4174.     if (reload_in[j] == 0)
  4175.       {
  4176.         /* But earlyclobber operands must stay as RELOAD_OTHER.  */
  4177.         for (i = 0; i < n_earlyclobbers; i++)
  4178.           if (rtx_equal_p (reload_out[j], reload_earlyclobbers[i]))
  4179.         break;
  4180.         if (i == n_earlyclobbers)
  4181.           reload_when_needed[j] = RELOAD_FOR_OUTPUT;
  4182.       }
  4183.     if (reload_out[j] == 0)
  4184.       reload_when_needed[j] = RELOAD_FOR_INPUT;
  4185.  
  4186.     if (reload_secondary_reload[j] >= 0
  4187.         && ! reload_needed_for_multiple[reload_secondary_reload[j]])
  4188.       reload_when_needed[reload_secondary_reload[j]]
  4189.         = reload_when_needed[j];
  4190.       }
  4191.  
  4192. #ifdef SMALL_REGISTER_CLASSES
  4193.   /* Don't bother with avoiding the return reg
  4194.      if we have no mandatory reload that could use it.  */
  4195.   if (avoid_return_reg)
  4196.     {
  4197.       int do_avoid = 0;
  4198.       int regno = REGNO (avoid_return_reg);
  4199.       int nregs
  4200.     = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  4201.       int r;
  4202.  
  4203.       for (r = regno; r < regno + nregs; r++)
  4204.     if (spill_reg_order[r] >= 0)
  4205.       for (j = 0; j < n_reloads; j++)
  4206.         if (!reload_optional[j] && reload_reg_rtx[j] == 0
  4207.         && (reload_in[j] != 0 || reload_out[j] != 0
  4208.             || reload_secondary_p[j])
  4209.         &&
  4210.         TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[j]], r))
  4211.           do_avoid = 1;
  4212.       if (!do_avoid)
  4213.     avoid_return_reg = 0;
  4214.     }
  4215. #endif /* SMALL_REGISTER_CLASSES */
  4216.  
  4217. #if 0  /* Not needed, now that we can always retry without inheritance.  */
  4218.   /* See if we have more mandatory reloads than spill regs.
  4219.      If so, then we cannot risk optimizations that could prevent
  4220.      reloads from sharing one spill register.
  4221.  
  4222.      Since we will try finding a better register than reload_reg_rtx
  4223.      unless it is equal to reload_in or reload_out, count such reloads.  */
  4224.  
  4225.   {
  4226.     int tem = 0;
  4227. #ifdef SMALL_REGISTER_CLASSES
  4228.     int tem = (avoid_return_reg != 0);
  4229. #endif
  4230.     for (j = 0; j < n_reloads; j++)
  4231.       if (! reload_optional[j]
  4232.       && (reload_in[j] != 0 || reload_out[j] != 0 || reload_secondary_p[j])
  4233.       && (reload_reg_rtx[j] == 0
  4234.           || (! rtx_equal_p (reload_reg_rtx[j], reload_in[j])
  4235.           && ! rtx_equal_p (reload_reg_rtx[j], reload_out[j]))))
  4236.     tem++;
  4237.     if (tem > n_spills)
  4238.       must_reuse = 1;
  4239.   }
  4240. #endif
  4241.  
  4242. #ifdef SMALL_REGISTER_CLASSES
  4243.   /* Don't use the subroutine call return reg for a reload
  4244.      if we are supposed to avoid it.  */
  4245.   if (avoid_return_reg)
  4246.     {
  4247.       int regno = REGNO (avoid_return_reg);
  4248.       int nregs
  4249.     = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  4250.       int r;
  4251.  
  4252.       for (r = regno; r < regno + nregs; r++)
  4253.     if (spill_reg_order[r] >= 0)
  4254.       SET_HARD_REG_BIT (reload_reg_used, r);
  4255.     }
  4256. #endif /* SMALL_REGISTER_CLASSES */
  4257.  
  4258.   /* In order to be certain of getting the registers we need,
  4259.      we must sort the reloads into order of increasing register class.
  4260.      Then our grabbing of reload registers will parallel the process
  4261.      that provided the reload registers.
  4262.  
  4263.      Also note whether any of the reloads wants a consecutive group of regs.
  4264.      If so, record the maximum size of the group desired and what
  4265.      register class contains all the groups needed by this insn.  */
  4266.  
  4267.   for (j = 0; j < n_reloads; j++)
  4268.     {
  4269.       reload_order[j] = j;
  4270.       reload_spill_index[j] = -1;
  4271.  
  4272.       reload_mode[j]
  4273.     = (reload_strict_low[j] && reload_out[j]
  4274.        ? GET_MODE (SUBREG_REG (reload_out[j]))
  4275.        : (reload_inmode[j] == VOIDmode
  4276.           || (GET_MODE_SIZE (reload_outmode[j])
  4277.           > GET_MODE_SIZE (reload_inmode[j])))
  4278.        ? reload_outmode[j] : reload_inmode[j]);
  4279.  
  4280.       reload_nregs[j] = CLASS_MAX_NREGS (reload_reg_class[j], reload_mode[j]);
  4281.  
  4282.       if (reload_nregs[j] > 1)
  4283.     {
  4284.       max_group_size = MAX (reload_nregs[j], max_group_size);
  4285.       group_class = reg_class_superunion[(int)reload_reg_class[j]][(int)group_class];
  4286.     }
  4287.  
  4288.       /* If we have already decided to use a certain register,
  4289.      don't use it in another way.  */
  4290.       if (reload_reg_rtx[j])
  4291.     mark_reload_reg_in_use (REGNO (reload_reg_rtx[j]),
  4292.                 reload_when_needed[j], reload_mode[j]);
  4293.     }
  4294.  
  4295.   if (n_reloads > 1)
  4296.     qsort (reload_order, n_reloads, sizeof (short), reload_reg_class_lower);
  4297.  
  4298.   bcopy (reload_reg_rtx, save_reload_reg_rtx, sizeof reload_reg_rtx);
  4299.   bcopy (reload_inherited, save_reload_inherited, sizeof reload_inherited);
  4300.   bcopy (reload_inheritance_insn, save_reload_inheritance_insn,
  4301.      sizeof reload_inheritance_insn);
  4302.   bcopy (reload_override_in, save_reload_override_in,
  4303.      sizeof reload_override_in);
  4304.   bcopy (reload_spill_index, save_reload_spill_index,
  4305.      sizeof reload_spill_index);
  4306.   COPY_HARD_REG_SET (save_reload_reg_used, reload_reg_used);
  4307.   COPY_HARD_REG_SET (save_reload_reg_used_at_all, reload_reg_used_at_all);
  4308.   COPY_HARD_REG_SET (save_reload_reg_used_in_output,
  4309.              reload_reg_used_in_output);
  4310.   COPY_HARD_REG_SET (save_reload_reg_used_in_input,
  4311.              reload_reg_used_in_input);
  4312.   COPY_HARD_REG_SET (save_reload_reg_used_in_input_addr,
  4313.              reload_reg_used_in_input_addr);
  4314.   COPY_HARD_REG_SET (save_reload_reg_used_in_output_addr,
  4315.              reload_reg_used_in_output_addr);
  4316.   COPY_HARD_REG_SET (save_reload_reg_used_in_op_addr,
  4317.              reload_reg_used_in_op_addr);
  4318.  
  4319.   /* If -O, try first with inheritance, then turning it off.
  4320.      If not -O, don't do inheritance.
  4321.      Using inheritance when not optimizing leads to paradoxes
  4322.      with fp on the 68k: fp numbers (not NaNs) fail to be equal to themselves
  4323.      because one side of the comparison might be inherited.  */
  4324.  
  4325.   for (inheritance = optimize > 0; inheritance >= 0; inheritance--)
  4326.     {
  4327.       /* Process the reloads in order of preference just found.
  4328.      Beyond this point, subregs can be found in reload_reg_rtx.
  4329.  
  4330.      This used to look for an existing reloaded home for all
  4331.      of the reloads, and only then perform any new reloads.
  4332.      But that could lose if the reloads were done out of reg-class order
  4333.      because a later reload with a looser constraint might have an old
  4334.      home in a register needed by an earlier reload with a tighter constraint.
  4335.  
  4336.      To solve this, we make two passes over the reloads, in the order
  4337.      described above.  In the first pass we try to inherit a reload
  4338.      from a previous insn.  If there is a later reload that needs a
  4339.      class that is a proper subset of the class being processed, we must
  4340.      also allocate a spill register during the first pass.
  4341.  
  4342.      Then make a second pass over the reloads to allocate any reloads
  4343.      that haven't been given registers yet.  */
  4344.  
  4345.       for (j = 0; j < n_reloads; j++)
  4346.     {
  4347.       register int r = reload_order[j];
  4348.  
  4349.       /* Ignore reloads that got marked inoperative.  */
  4350.       if (reload_out[r] == 0 && reload_in[r] == 0 && ! reload_secondary_p[r])
  4351.         continue;
  4352.  
  4353.       /* If find_reloads chose a to use reload_in or reload_out as a reload
  4354.          register, we don't need to chose one.  Otherwise, try even if it found
  4355.          one since we might save an insn if we find the value lying around.  */
  4356.       if (reload_in[r] != 0 && reload_reg_rtx[r] != 0
  4357.           && (rtx_equal_p (reload_in[r], reload_reg_rtx[r])
  4358.           || rtx_equal_p (reload_out[r], reload_reg_rtx[r])))
  4359.         continue;
  4360.  
  4361. #if 0 /* No longer needed for correct operation.
  4362.      It might give better code, or might not; worth an experiment?  */
  4363.       /* If this is an optional reload, we can't inherit from earlier insns
  4364.          until we are sure that any non-optional reloads have been allocated.
  4365.          The following code takes advantage of the fact that optional reloads
  4366.          are at the end of reload_order.  */
  4367.       if (reload_optional[r] != 0)
  4368.         for (i = 0; i < j; i++)
  4369.           if ((reload_out[reload_order[i]] != 0
  4370.            || reload_in[reload_order[i]] != 0
  4371.            || reload_secondary_p[reload_order[i]])
  4372.           && ! reload_optional[reload_order[i]]
  4373.           && reload_reg_rtx[reload_order[i]] == 0)
  4374.         allocate_reload_reg (reload_order[i], insn, 0, inheritance);
  4375. #endif
  4376.  
  4377.       /* First see if this pseudo is already available as reloaded
  4378.          for a previous insn.  We cannot try to inherit for reloads
  4379.          that are smaller than the maximum number of registers needed
  4380.          for groups unless the register we would allocate cannot be used
  4381.          for the groups.
  4382.  
  4383.          We could check here to see if this is a secondary reload for
  4384.          an object that is already in a register of the desired class.
  4385.          This would avoid the need for the secondary reload register.
  4386.          But this is complex because we can't easily determine what
  4387.          objects might want to be loaded via this reload.  So let a register
  4388.          be allocated here.  In `emit_reload_insns' we suppress one of the
  4389.          loads in the case described above.  */
  4390.  
  4391.       if (inheritance)
  4392.         {
  4393.           register int regno = -1;
  4394.           enum machine_mode mode;
  4395.  
  4396.           if (reload_in[r] == 0)
  4397.         ;
  4398.           else if (GET_CODE (reload_in[r]) == REG)
  4399.         {
  4400.           regno = REGNO (reload_in[r]);
  4401.           mode = GET_MODE (reload_in[r]);
  4402.         }
  4403.           else if (GET_CODE (reload_in_reg[r]) == REG)
  4404.         {
  4405.           regno = REGNO (reload_in_reg[r]);
  4406.           mode = GET_MODE (reload_in_reg[r]);
  4407.         }
  4408. #if 0
  4409.           /* This won't work, since REGNO can be a pseudo reg number.
  4410.          Also, it takes much more hair to keep track of all the things
  4411.          that can invalidate an inherited reload of part of a pseudoreg.  */
  4412.           else if (GET_CODE (reload_in[r]) == SUBREG
  4413.                && GET_CODE (SUBREG_REG (reload_in[r])) == REG)
  4414.         regno = REGNO (SUBREG_REG (reload_in[r])) + SUBREG_WORD (reload_in[r]);
  4415. #endif
  4416.  
  4417.           if (regno >= 0 && reg_last_reload_reg[regno] != 0)
  4418.         {
  4419.           i = spill_reg_order[REGNO (reg_last_reload_reg[regno])];
  4420.  
  4421.           if (reg_reloaded_contents[i] == regno
  4422.               && (GET_MODE_SIZE (GET_MODE (reg_last_reload_reg[regno]))
  4423.               >= GET_MODE_SIZE (mode))
  4424.               && HARD_REGNO_MODE_OK (spill_regs[i], reload_mode[r])
  4425.               && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  4426.                         spill_regs[i])
  4427.               && (reload_nregs[r] == max_group_size
  4428.               || ! TEST_HARD_REG_BIT (reg_class_contents[(int) group_class],
  4429.                           spill_regs[i]))
  4430.               && reload_reg_free_p (spill_regs[i], reload_when_needed[r])
  4431.               && reload_reg_free_before_p (spill_regs[i],
  4432.                            reload_when_needed[r]))
  4433.             {
  4434.               /* If a group is needed, verify that all the subsequent
  4435.              registers still have their values intact. */
  4436.               int nr
  4437.             = HARD_REGNO_NREGS (spill_regs[i], reload_mode[r]);
  4438.               int k;
  4439.  
  4440.               for (k = 1; k < nr; k++)
  4441.             if (reg_reloaded_contents[spill_reg_order[spill_regs[i] + k]]
  4442.                 != regno)
  4443.               break;
  4444.  
  4445.               if (k == nr)
  4446.             {
  4447.               /* Mark the register as in use for this part of
  4448.                  the insn.  */
  4449.               mark_reload_reg_in_use (spill_regs[i],
  4450.                           reload_when_needed[r],
  4451.                           reload_mode[r]);
  4452.               reload_reg_rtx[r] = reg_last_reload_reg[regno];
  4453.               reload_inherited[r] = 1;
  4454.               reload_inheritance_insn[r] = reg_reloaded_insn[i];
  4455.               reload_spill_index[r] = i;
  4456.             }
  4457.             }
  4458.         }
  4459.         }
  4460.  
  4461.       /* Here's another way to see if the value is already lying around.  */
  4462.       if (inheritance
  4463.           && reload_in[r] != 0
  4464.           && ! reload_inherited[r]
  4465.           && reload_out[r] == 0
  4466.           && (CONSTANT_P (reload_in[r])
  4467.           || GET_CODE (reload_in[r]) == PLUS
  4468.           || GET_CODE (reload_in[r]) == REG
  4469.           || GET_CODE (reload_in[r]) == MEM)
  4470.           && (reload_nregs[r] == max_group_size
  4471.           || ! reg_classes_intersect_p (reload_reg_class[r], group_class)))
  4472.         {
  4473.           register rtx equiv
  4474.         = find_equiv_reg (reload_in[r], insn, reload_reg_class[r],
  4475.                   -1, NULL_PTR, 0, reload_mode[r]);
  4476.           int regno;
  4477.  
  4478.           if (equiv != 0)
  4479.         {
  4480.           if (GET_CODE (equiv) == REG)
  4481.             regno = REGNO (equiv);
  4482.           else if (GET_CODE (equiv) == SUBREG)
  4483.             {
  4484.               regno = REGNO (SUBREG_REG (equiv));
  4485.               if (regno < FIRST_PSEUDO_REGISTER)
  4486.             regno += SUBREG_WORD (equiv);
  4487.             }
  4488.           else
  4489.             abort ();
  4490.         }
  4491.  
  4492.           /* If we found a spill reg, reject it unless it is free
  4493.          and of the desired class.  */
  4494.           if (equiv != 0
  4495.           && ((spill_reg_order[regno] >= 0
  4496.                && ! reload_reg_free_before_p (regno,
  4497.                               reload_when_needed[r]))
  4498.               || ! TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  4499.                           regno)))
  4500.         equiv = 0;
  4501.  
  4502.           if (equiv != 0 && TEST_HARD_REG_BIT (reload_reg_used_at_all, regno))
  4503.         equiv = 0;
  4504.  
  4505.           if (equiv != 0 && ! HARD_REGNO_MODE_OK (regno, reload_mode[r]))
  4506.         equiv = 0;
  4507.  
  4508.           /* We found a register that contains the value we need.
  4509.          If this register is the same as an `earlyclobber' operand
  4510.          of the current insn, just mark it as a place to reload from
  4511.          since we can't use it as the reload register itself.  */
  4512.  
  4513.           if (equiv != 0)
  4514.         for (i = 0; i < n_earlyclobbers; i++)
  4515.           if (reg_overlap_mentioned_for_reload_p (equiv,
  4516.                               reload_earlyclobbers[i]))
  4517.             {
  4518.               reload_override_in[r] = equiv;
  4519.               equiv = 0;
  4520.               break;
  4521.             }
  4522.  
  4523.           /* JRV: If the equiv register we have found is explicitly
  4524.          clobbered in the current insn, mark but don't use, as above. */
  4525.  
  4526.           if (equiv != 0 && regno_clobbered_p (regno, insn))
  4527.         {
  4528.           reload_override_in[r] = equiv;
  4529.           equiv = 0;
  4530.         }
  4531.  
  4532.           /* If we found an equivalent reg, say no code need be generated
  4533.          to load it, and use it as our reload reg.  */
  4534.           if (equiv != 0 && regno != FRAME_POINTER_REGNUM)
  4535.         {
  4536.           reload_reg_rtx[r] = equiv;
  4537.           reload_inherited[r] = 1;
  4538.           /* If it is a spill reg,
  4539.              mark the spill reg as in use for this insn.  */
  4540.           i = spill_reg_order[regno];
  4541.           if (i >= 0)
  4542.             mark_reload_reg_in_use (regno, reload_when_needed[r],
  4543.                         reload_mode[r]);
  4544.         }
  4545.         }
  4546.  
  4547.       /* If we found a register to use already, or if this is an optional
  4548.          reload, we are done.  */
  4549.       if (reload_reg_rtx[r] != 0 || reload_optional[r] != 0)
  4550.         continue;
  4551.  
  4552. #if 0 /* No longer needed for correct operation.  Might or might not
  4553.      give better code on the average.  Want to experiment?  */
  4554.  
  4555.       /* See if there is a later reload that has a class different from our
  4556.          class that intersects our class or that requires less register
  4557.          than our reload.  If so, we must allocate a register to this
  4558.          reload now, since that reload might inherit a previous reload
  4559.          and take the only available register in our class.  Don't do this
  4560.          for optional reloads since they will force all previous reloads
  4561.          to be allocated.  Also don't do this for reloads that have been
  4562.          turned off.  */
  4563.  
  4564.       for (i = j + 1; i < n_reloads; i++)
  4565.         {
  4566.           int s = reload_order[i];
  4567.  
  4568.           if ((reload_in[s] == 0 && reload_out[s] == 0
  4569.            && ! reload_secondary_p[s])
  4570.           || reload_optional[s])
  4571.         continue;
  4572.  
  4573.           if ((reload_reg_class[s] != reload_reg_class[r]
  4574.            && reg_classes_intersect_p (reload_reg_class[r],
  4575.                            reload_reg_class[s]))
  4576.           || reload_nregs[s] < reload_nregs[r])
  4577.           break;
  4578.         }
  4579.  
  4580.       if (i == n_reloads)
  4581.         continue;
  4582.  
  4583.       allocate_reload_reg (r, insn, j == n_reloads - 1, inheritance);
  4584. #endif
  4585.     }
  4586.  
  4587.       /* Now allocate reload registers for anything non-optional that
  4588.      didn't get one yet.  */
  4589.       for (j = 0; j < n_reloads; j++)
  4590.     {
  4591.       register int r = reload_order[j];
  4592.  
  4593.       /* Ignore reloads that got marked inoperative.  */
  4594.       if (reload_out[r] == 0 && reload_in[r] == 0 && ! reload_secondary_p[r])
  4595.         continue;
  4596.  
  4597.       /* Skip reloads that already have a register allocated or are
  4598.          optional. */
  4599.       if (reload_reg_rtx[r] != 0 || reload_optional[r])
  4600.         continue;
  4601.  
  4602.       if (! allocate_reload_reg (r, insn, j == n_reloads - 1, inheritance))
  4603.         break;
  4604.     }
  4605.  
  4606.       /* If that loop got all the way, we have won.  */
  4607.       if (j == n_reloads)
  4608.     break;
  4609.  
  4610.     fail:
  4611.       /* Loop around and try without any inheritance.  */
  4612.       /* First undo everything done by the failed attempt
  4613.      to allocate with inheritance.  */
  4614.       bcopy (save_reload_reg_rtx, reload_reg_rtx, sizeof reload_reg_rtx);
  4615.       bcopy (save_reload_inherited, reload_inherited, sizeof reload_inherited);
  4616.       bcopy (save_reload_inheritance_insn, reload_inheritance_insn,
  4617.          sizeof reload_inheritance_insn);
  4618.       bcopy (save_reload_override_in, reload_override_in,
  4619.          sizeof reload_override_in);
  4620.       bcopy (save_reload_spill_index, reload_spill_index,
  4621.          sizeof reload_spill_index);
  4622.       COPY_HARD_REG_SET (reload_reg_used, save_reload_reg_used);
  4623.       COPY_HARD_REG_SET (reload_reg_used_at_all, save_reload_reg_used_at_all);
  4624.       COPY_HARD_REG_SET (reload_reg_used_in_input,
  4625.              save_reload_reg_used_in_input);
  4626.       COPY_HARD_REG_SET (reload_reg_used_in_output,
  4627.              save_reload_reg_used_in_output);
  4628.       COPY_HARD_REG_SET (reload_reg_used_in_input_addr,
  4629.              save_reload_reg_used_in_input_addr);
  4630.       COPY_HARD_REG_SET (reload_reg_used_in_output_addr,
  4631.              save_reload_reg_used_in_output_addr);
  4632.       COPY_HARD_REG_SET (reload_reg_used_in_op_addr,
  4633.              save_reload_reg_used_in_op_addr);
  4634.     }
  4635.  
  4636.   /* If we thought we could inherit a reload, because it seemed that
  4637.      nothing else wanted the same reload register earlier in the insn,
  4638.      verify that assumption, now that all reloads have been assigned.  */
  4639.  
  4640.   for (j = 0; j < n_reloads; j++)
  4641.     {
  4642.       register int r = reload_order[j];
  4643.  
  4644.       if (reload_inherited[r] && reload_reg_rtx[r] != 0
  4645.       && ! reload_reg_free_before_p (true_regnum (reload_reg_rtx[r]),
  4646.                      reload_when_needed[r]))
  4647.     reload_inherited[r] = 0;
  4648.  
  4649.       /* If we found a better place to reload from,
  4650.      validate it in the same fashion, if it is a reload reg.  */
  4651.       if (reload_override_in[r]
  4652.       && (GET_CODE (reload_override_in[r]) == REG
  4653.           || GET_CODE (reload_override_in[r]) == SUBREG))
  4654.     {
  4655.       int regno = true_regnum (reload_override_in[r]);
  4656.       if (spill_reg_order[regno] >= 0
  4657.           && ! reload_reg_free_before_p (regno, reload_when_needed[r]))
  4658.         reload_override_in[r] = 0;
  4659.     }
  4660.     }
  4661.  
  4662.   /* Now that reload_override_in is known valid,
  4663.      actually override reload_in.  */
  4664.   for (j = 0; j < n_reloads; j++)
  4665.     if (reload_override_in[j])
  4666.       reload_in[j] = reload_override_in[j];
  4667.  
  4668.   /* If this reload won't be done because it has been cancelled or is
  4669.      optional and not inherited, clear reload_reg_rtx so other
  4670.      routines (such as subst_reloads) don't get confused.  */
  4671.   for (j = 0; j < n_reloads; j++)
  4672.     if ((reload_optional[j] && ! reload_inherited[j])
  4673.     || (reload_in[j] == 0 && reload_out[j] == 0
  4674.         && ! reload_secondary_p[j]))
  4675.       reload_reg_rtx[j] = 0;
  4676.  
  4677.   /* Record which pseudos and which spill regs have output reloads.  */
  4678.   for (j = 0; j < n_reloads; j++)
  4679.     {
  4680.       register int r = reload_order[j];
  4681.  
  4682.       i = reload_spill_index[r];
  4683.  
  4684.       /* I is nonneg if this reload used one of the spill regs.
  4685.      If reload_reg_rtx[r] is 0, this is an optional reload
  4686.      that we opted to ignore.  */
  4687.       if (reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG
  4688.       && reload_reg_rtx[r] != 0)
  4689.     {
  4690.       register int nregno = REGNO (reload_out[r]);
  4691.       int nr = 1;
  4692.  
  4693.       if (nregno < FIRST_PSEUDO_REGISTER)
  4694.         nr = HARD_REGNO_NREGS (nregno, reload_mode[r]);
  4695.  
  4696.       while (--nr >= 0)
  4697.         reg_has_output_reload[nregno + nr] = 1;
  4698.  
  4699.       if (i >= 0)
  4700.         {
  4701.           nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode[r]);
  4702.           while (--nr >= 0)
  4703.         SET_HARD_REG_BIT (reg_is_output_reload, spill_regs[i] + nr);
  4704.         }
  4705.  
  4706.       if (reload_when_needed[r] != RELOAD_OTHER
  4707.           && reload_when_needed[r] != RELOAD_FOR_OUTPUT)
  4708.         abort ();
  4709.     }
  4710.     }
  4711. }
  4712.  
  4713. /* Output insns to reload values in and out of the chosen reload regs.  */
  4714.  
  4715. static void
  4716. emit_reload_insns (insn)
  4717.      rtx insn;
  4718. {
  4719.   register int j;
  4720.   rtx following_insn = NEXT_INSN (insn);
  4721.   rtx before_insn = insn;
  4722.   rtx first_output_reload_insn = NEXT_INSN (insn);
  4723.   rtx first_other_reload_insn = insn;
  4724.   rtx first_operand_address_reload_insn = insn;
  4725.   int special;
  4726.   /* Values to be put in spill_reg_store are put here first.  */
  4727.   rtx new_spill_reg_store[FIRST_PSEUDO_REGISTER];
  4728.  
  4729.   /* If this is a CALL_INSN preceded by USE insns, any reload insns
  4730.      must go in front of the first USE insn, not in front of INSN.  */
  4731.  
  4732.   if (GET_CODE (insn) == CALL_INSN && GET_CODE (PREV_INSN (insn)) == INSN
  4733.       && GET_CODE (PATTERN (PREV_INSN (insn))) == USE)
  4734.     while (GET_CODE (PREV_INSN (before_insn)) == INSN
  4735.        && GET_CODE (PATTERN (PREV_INSN (before_insn))) == USE)
  4736.       first_other_reload_insn = first_operand_address_reload_insn
  4737.     = before_insn = PREV_INSN (before_insn);
  4738.  
  4739.   /* Now output the instructions to copy the data into and out of the
  4740.      reload registers.  Do these in the order that the reloads were reported,
  4741.      since reloads of base and index registers precede reloads of operands
  4742.      and the operands may need the base and index registers reloaded.  */
  4743.  
  4744.   for (j = 0; j < n_reloads; j++)
  4745.     {
  4746.       register rtx old;
  4747.       rtx oldequiv_reg = 0;
  4748.       rtx this_reload_insn = 0;
  4749.       rtx store_insn = 0;
  4750.  
  4751.       old = reload_in[j];
  4752.       if (old != 0 && ! reload_inherited[j]
  4753.       && ! rtx_equal_p (reload_reg_rtx[j], old)
  4754.       && reload_reg_rtx[j] != 0)
  4755.     {
  4756.       register rtx reloadreg = reload_reg_rtx[j];
  4757.       rtx oldequiv = 0;
  4758.       enum machine_mode mode;
  4759.       rtx where;
  4760.       rtx reload_insn;
  4761.  
  4762.       /* Determine the mode to reload in.
  4763.          This is very tricky because we have three to choose from.
  4764.          There is the mode the insn operand wants (reload_inmode[J]).
  4765.          There is the mode of the reload register RELOADREG.
  4766.          There is the intrinsic mode of the operand, which we could find
  4767.          by stripping some SUBREGs.
  4768.          It turns out that RELOADREG's mode is irrelevant:
  4769.          we can change that arbitrarily.
  4770.  
  4771.          Consider (SUBREG:SI foo:QI) as an operand that must be SImode;
  4772.          then the reload reg may not support QImode moves, so use SImode.
  4773.          If foo is in memory due to spilling a pseudo reg, this is safe,
  4774.          because the QImode value is in the least significant part of a
  4775.          slot big enough for a SImode.  If foo is some other sort of
  4776.          memory reference, then it is impossible to reload this case,
  4777.          so previous passes had better make sure this never happens.
  4778.  
  4779.          Then consider a one-word union which has SImode and one of its
  4780.          members is a float, being fetched as (SUBREG:SF union:SI).
  4781.          We must fetch that as SFmode because we could be loading into
  4782.          a float-only register.  In this case OLD's mode is correct.
  4783.  
  4784.          Consider an immediate integer: it has VOIDmode.  Here we need
  4785.          to get a mode from something else.
  4786.  
  4787.          In some cases, there is a fourth mode, the operand's
  4788.          containing mode.  If the insn specifies a containing mode for
  4789.          this operand, it overrides all others.
  4790.  
  4791.          I am not sure whether the algorithm here is always right,
  4792.          but it does the right things in those cases.  */
  4793.  
  4794.       mode = GET_MODE (old);
  4795.       if (mode == VOIDmode)
  4796.         mode = reload_inmode[j];
  4797.       if (reload_strict_low[j])
  4798.         mode = GET_MODE (SUBREG_REG (reload_in[j]));
  4799.  
  4800. #ifdef SECONDARY_INPUT_RELOAD_CLASS
  4801.       /* If we need a secondary register for this operation, see if
  4802.          the value is already in a register in that class.  Don't
  4803.          do this if the secondary register will be used as a scratch
  4804.          register.  */
  4805.  
  4806.       if (reload_secondary_reload[j] >= 0
  4807.           && reload_secondary_icode[j] == CODE_FOR_nothing
  4808.           && optimize)
  4809.         oldequiv
  4810.           = find_equiv_reg (old, insn,
  4811.                 reload_reg_class[reload_secondary_reload[j]],
  4812.                 -1, NULL_PTR, 0, mode);
  4813. #endif
  4814.  
  4815.       /* If reloading from memory, see if there is a register
  4816.          that already holds the same value.  If so, reload from there.
  4817.          We can pass 0 as the reload_reg_p argument because
  4818.          any other reload has either already been emitted,
  4819.          in which case find_equiv_reg will see the reload-insn,
  4820.          or has yet to be emitted, in which case it doesn't matter
  4821.          because we will use this equiv reg right away.  */
  4822.  
  4823.       if (oldequiv == 0 && optimize
  4824.           && (GET_CODE (old) == MEM
  4825.           || (GET_CODE (old) == REG
  4826.               && REGNO (old) >= FIRST_PSEUDO_REGISTER
  4827.               && reg_renumber[REGNO (old)] < 0)))
  4828.         oldequiv = find_equiv_reg (old, insn, GENERAL_REGS,
  4829.                        -1, NULL_PTR, 0, mode);
  4830.  
  4831.       if (oldequiv)
  4832.         {
  4833.           int regno = true_regnum (oldequiv);
  4834.  
  4835.           /* If OLDEQUIV is a spill register, don't use it for this
  4836.          if any other reload needs it at an earlier stage of this insn
  4837.          or at this stage.  */
  4838.           if (spill_reg_order[regno] >= 0
  4839.           && (! reload_reg_free_p (regno, reload_when_needed[j])
  4840.               || ! reload_reg_free_before_p (regno,
  4841.                              reload_when_needed[j])))
  4842.         oldequiv = 0;
  4843.  
  4844.           /* If OLDEQUIV is not a spill register,
  4845.          don't use it if any other reload wants it.  */
  4846.           if (spill_reg_order[regno] < 0)
  4847.         {
  4848.           int k;
  4849.           for (k = 0; k < n_reloads; k++)
  4850.             if (reload_reg_rtx[k] != 0 && k != j
  4851.             && reg_overlap_mentioned_for_reload_p (reload_reg_rtx[k],
  4852.                                    oldequiv))
  4853.               {
  4854.             oldequiv = 0;
  4855.             break;
  4856.               }
  4857.         }
  4858.         }
  4859.  
  4860.       if (oldequiv == 0)
  4861.         oldequiv = old;
  4862.       else if (GET_CODE (oldequiv) == REG)
  4863.         oldequiv_reg = oldequiv;
  4864.       else if (GET_CODE (oldequiv) == SUBREG)
  4865.         oldequiv_reg = SUBREG_REG (oldequiv);
  4866.  
  4867.       /* Encapsulate both RELOADREG and OLDEQUIV into that mode,
  4868.          then load RELOADREG from OLDEQUIV.  */
  4869.  
  4870.       if (GET_MODE (reloadreg) != mode)
  4871.         reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  4872.       while (GET_CODE (oldequiv) == SUBREG && GET_MODE (oldequiv) != mode)
  4873.         oldequiv = SUBREG_REG (oldequiv);
  4874.       if (GET_MODE (oldequiv) != VOIDmode
  4875.           && mode != GET_MODE (oldequiv))
  4876.         oldequiv = gen_rtx (SUBREG, mode, oldequiv, 0);
  4877.  
  4878.       /* Decide where to put reload insn for this reload.  */
  4879.       switch (reload_when_needed[j])
  4880.         {
  4881.         case RELOAD_FOR_INPUT:
  4882.         case RELOAD_OTHER:
  4883.           where = first_operand_address_reload_insn;
  4884.           break;
  4885.         case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  4886.           where = first_other_reload_insn;
  4887.           break;
  4888.         case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  4889.           where = first_output_reload_insn;
  4890.           break;
  4891.         case RELOAD_FOR_OPERAND_ADDRESS:
  4892.           where = before_insn;
  4893.         }
  4894.  
  4895.       special = 0;
  4896.  
  4897.       /* Auto-increment addresses must be reloaded in a special way.  */
  4898.       if (GET_CODE (oldequiv) == POST_INC
  4899.           || GET_CODE (oldequiv) == POST_DEC
  4900.           || GET_CODE (oldequiv) == PRE_INC
  4901.           || GET_CODE (oldequiv) == PRE_DEC)
  4902.         {
  4903.           /* We are not going to bother supporting the case where a
  4904.          incremented register can't be copied directly from
  4905.          OLDEQUIV since this seems highly unlikely.  */
  4906.           if (reload_secondary_reload[j] >= 0)
  4907.         abort ();
  4908.           /* Prevent normal processing of this reload.  */
  4909.           special = 1;
  4910.           /* Output a special code sequence for this case.  */
  4911.           this_reload_insn
  4912.         = inc_for_reload (reloadreg, oldequiv, reload_inc[j], where);
  4913.         }
  4914.  
  4915.       /* If we are reloading a pseudo-register that was set by the previous
  4916.          insn, see if we can get rid of that pseudo-register entirely
  4917.          by redirecting the previous insn into our reload register.  */
  4918.  
  4919.       else if (optimize && GET_CODE (old) == REG
  4920.            && REGNO (old) >= FIRST_PSEUDO_REGISTER
  4921.            && dead_or_set_p (insn, old)
  4922.            /* This is unsafe if some other reload
  4923.               uses the same reg first.  */
  4924.            && (reload_when_needed[j] == RELOAD_OTHER
  4925.                || reload_when_needed[j] == RELOAD_FOR_INPUT
  4926.                || reload_when_needed[j] == RELOAD_FOR_INPUT_RELOAD_ADDRESS))
  4927.         {
  4928.           rtx temp = PREV_INSN (insn);
  4929.           while (temp && GET_CODE (temp) == NOTE)
  4930.         temp = PREV_INSN (temp);
  4931.           if (temp
  4932.           && GET_CODE (temp) == INSN
  4933.           && GET_CODE (PATTERN (temp)) == SET
  4934.           && SET_DEST (PATTERN (temp)) == old
  4935.           /* Make sure we can access insn_operand_constraint.  */
  4936.           && asm_noperands (PATTERN (temp)) < 0
  4937.           /* This is unsafe if prev insn rejects our reload reg.  */
  4938.           && constraint_accepts_reg_p (insn_operand_constraint[recog_memoized (temp)][0],
  4939.                            reloadreg)
  4940.           /* This is unsafe if operand occurs more than once in current
  4941.              insn.  Perhaps some occurrences aren't reloaded.  */
  4942.           && count_occurrences (PATTERN (insn), old) == 1
  4943.           /* Don't risk splitting a matching pair of operands.  */
  4944.           && ! reg_mentioned_p (old, SET_SRC (PATTERN (temp))))
  4945.         {
  4946.           /* Store into the reload register instead of the pseudo.  */
  4947.           SET_DEST (PATTERN (temp)) = reloadreg;
  4948.           /* If these are the only uses of the pseudo reg,
  4949.              pretend for GDB it lives in the reload reg we used.  */
  4950.           if (reg_n_deaths[REGNO (old)] == 1
  4951.               && reg_n_sets[REGNO (old)] == 1)
  4952.             {
  4953.               reg_renumber[REGNO (old)] = REGNO (reload_reg_rtx[j]);
  4954.               alter_reg (REGNO (old), -1);
  4955.             }
  4956.           special = 1;
  4957.         }
  4958.         }
  4959.  
  4960.       /* We can't do that, so output an insn to load RELOADREG.
  4961.          Keep them in the following order:
  4962.          all reloads for input reload addresses,
  4963.          all reloads for ordinary input operands,
  4964.          all reloads for addresses of non-reloaded operands,
  4965.          the insn being reloaded,
  4966.          all reloads for addresses of output reloads,
  4967.          the output reloads.  */
  4968.       if (! special)
  4969.         {
  4970. #ifdef SECONDARY_INPUT_RELOAD_CLASS
  4971.           rtx second_reload_reg = 0;
  4972.           enum insn_code icode;
  4973.  
  4974.           /* If we have a secondary reload, pick up the secondary register
  4975.          and icode, if any.  If OLDEQUIV and OLD are different or
  4976.          if this is an in-out reload, recompute whether or not we
  4977.          still need a secondary register and what the icode should
  4978.          be.  If we still need a secondary register and the class or
  4979.          icode is different, go back to reloading from OLD if using
  4980.          OLDEQUIV means that we got the wrong type of register.  We
  4981.          cannot have different class or icode due to an in-out reload
  4982.          because we don't make such reloads when both the input and
  4983.          output need secondary reload registers.  */
  4984.  
  4985.           if (reload_secondary_reload[j] >= 0)
  4986.         {
  4987.           int secondary_reload = reload_secondary_reload[j];
  4988.           rtx real_oldequiv = oldequiv;
  4989.           rtx real_old = old;
  4990.  
  4991.           /* If OLDEQUIV is a pseudo with a MEM, get the real MEM
  4992.              and similarly for OLD.
  4993.              See comments in find_secondary_reload in reload.c.  */
  4994.           if (GET_CODE (oldequiv) == REG
  4995.               && REGNO (oldequiv) >= FIRST_PSEUDO_REGISTER
  4996.               && reg_equiv_mem[REGNO (oldequiv)] != 0)
  4997.             real_oldequiv = reg_equiv_mem[REGNO (oldequiv)];
  4998.  
  4999.           if (GET_CODE (old) == REG
  5000.               && REGNO (old) >= FIRST_PSEUDO_REGISTER
  5001.               && reg_equiv_mem[REGNO (old)] != 0)
  5002.             real_old = reg_equiv_mem[REGNO (old)];
  5003.  
  5004.           second_reload_reg = reload_reg_rtx[secondary_reload];
  5005.           icode = reload_secondary_icode[j];
  5006.  
  5007.           if ((old != oldequiv && ! rtx_equal_p (old, oldequiv))
  5008.               || (reload_in[j] != 0 && reload_out[j] != 0))
  5009.             {
  5010.               enum reg_class new_class
  5011.             = SECONDARY_INPUT_RELOAD_CLASS (reload_reg_class[j],
  5012.                             mode, real_oldequiv);
  5013.  
  5014.               if (new_class == NO_REGS)
  5015.             second_reload_reg = 0;
  5016.               else
  5017.             {
  5018.               enum insn_code new_icode;
  5019.               enum machine_mode new_mode;
  5020.  
  5021.               if (! TEST_HARD_REG_BIT (reg_class_contents[(int) new_class],
  5022.                            REGNO (second_reload_reg)))
  5023.                 oldequiv = old, real_oldequiv = real_old;
  5024.               else
  5025.                 {
  5026.                   new_icode = reload_in_optab[(int) mode];
  5027.                   if (new_icode != CODE_FOR_nothing
  5028.                   && ((insn_operand_predicate[(int) new_icode][0]
  5029.                        && ! ((*insn_operand_predicate[(int) new_icode][0])
  5030.                          (reloadreg, mode)))
  5031.                       || (insn_operand_predicate[(int) new_icode][1]
  5032.                       && ! ((*insn_operand_predicate[(int) new_icode][1])
  5033.                         (real_oldequiv, mode)))))
  5034.                 new_icode = CODE_FOR_nothing;
  5035.  
  5036.                   if (new_icode == CODE_FOR_nothing)
  5037.                 new_mode = mode;
  5038.                   else
  5039.                 new_mode = insn_operand_mode[new_icode][2];
  5040.  
  5041.                   if (GET_MODE (second_reload_reg) != new_mode)
  5042.                 {
  5043.                   if (!HARD_REGNO_MODE_OK (REGNO (second_reload_reg),
  5044.                                new_mode))
  5045.                     oldequiv = old, real_oldequiv = real_old;
  5046.                   else
  5047.                     second_reload_reg
  5048.                       = gen_rtx (REG, new_mode,
  5049.                          REGNO (second_reload_reg));
  5050.                 }
  5051.                 }
  5052.             }
  5053.             }
  5054.  
  5055.           /* If we still need a secondary reload register, check
  5056.              to see if it is being used as a scratch or intermediate
  5057.              register and generate code appropriately.  If we need
  5058.              a scratch register, use REAL_OLDEQUIV since the form of
  5059.              the insn may depend on the actual address if it is 
  5060.              a MEM.  */
  5061.  
  5062.           if (second_reload_reg)
  5063.             {
  5064.               if (icode != CODE_FOR_nothing)
  5065.             {
  5066.               reload_insn = emit_insn_before (GEN_FCN (icode)
  5067.                               (reloadreg,
  5068.                                real_oldequiv,
  5069.                                second_reload_reg),
  5070.                               where);
  5071.               if (this_reload_insn == 0)
  5072.                 this_reload_insn = reload_insn;
  5073.               special = 1;
  5074.             }
  5075.               else
  5076.             {
  5077.               /* See if we need a scratch register to load the
  5078.                  intermediate register (a tertiary reload).  */
  5079.               enum insn_code tertiary_icode
  5080.                 = reload_secondary_icode[secondary_reload];
  5081.  
  5082.               if (tertiary_icode != CODE_FOR_nothing)
  5083.                 {
  5084.                   rtx third_reload_reg
  5085.                     = reload_reg_rtx[reload_secondary_reload[secondary_reload]];
  5086.  
  5087.                   reload_insn
  5088.                 = emit_insn_before ((GEN_FCN (tertiary_icode)
  5089.                              (second_reload_reg,
  5090.                               real_oldequiv,
  5091.                               third_reload_reg)),
  5092.                             where);
  5093.                   if (this_reload_insn == 0)
  5094.                 this_reload_insn = reload_insn;
  5095.                 }
  5096.               else
  5097.                 {
  5098.                   reload_insn
  5099.                 = gen_input_reload (second_reload_reg,
  5100.                             oldequiv, where);
  5101.                   if (this_reload_insn == 0)
  5102.                 this_reload_insn = reload_insn;
  5103.                   oldequiv = second_reload_reg;
  5104.                 }
  5105.             }
  5106.             }
  5107.         }
  5108. #endif
  5109.  
  5110.           if (! special)
  5111.         {
  5112.           reload_insn = gen_input_reload (reloadreg, oldequiv, where);
  5113.           if (this_reload_insn == 0)
  5114.             this_reload_insn = reload_insn;
  5115.         }
  5116.  
  5117. #if defined(SECONDARY_INPUT_RELOAD_CLASS) && defined(PRESERVE_DEATH_INFO_REGNO_P)
  5118.           /* We may have to make a REG_DEAD note for the secondary reload
  5119.          register in the insns we just made.  Find the last insn that
  5120.          mentioned the register.  */
  5121.           if (! special && second_reload_reg
  5122.           && PRESERVE_DEATH_INFO_REGNO_P (REGNO (second_reload_reg)))
  5123.         {
  5124.           rtx prev;
  5125.  
  5126.           for (prev = where;
  5127.                prev != PREV_INSN (this_reload_insn);
  5128.                prev = PREV_INSN (prev))
  5129.             if (GET_RTX_CLASS (GET_CODE (prev) == 'i')
  5130.             && reg_overlap_mentioned_for_reload_p (second_reload_reg,
  5131.                                    PATTERN (prev)))
  5132.               {
  5133.             REG_NOTES (prev) = gen_rtx (EXPR_LIST, REG_DEAD,
  5134.                             second_reload_reg,
  5135.                             REG_NOTES (prev));
  5136.             break;
  5137.               }
  5138.         }
  5139. #endif
  5140.         }
  5141.  
  5142.       /* Update where to put other reload insns.  */
  5143.       if (this_reload_insn)
  5144.         switch (reload_when_needed[j])
  5145.           {
  5146.           case RELOAD_FOR_INPUT:
  5147.           case RELOAD_OTHER:
  5148.         if (first_other_reload_insn == first_operand_address_reload_insn)
  5149.           first_other_reload_insn = this_reload_insn;
  5150.         break;
  5151.           case RELOAD_FOR_OPERAND_ADDRESS:
  5152.         if (first_operand_address_reload_insn == before_insn)
  5153.           first_operand_address_reload_insn = this_reload_insn;
  5154.         if (first_other_reload_insn == before_insn)
  5155.           first_other_reload_insn = this_reload_insn;
  5156.           }
  5157.  
  5158.       /* reload_inc[j] was formerly processed here.  */
  5159.     }
  5160.  
  5161.       /* Add a note saying the input reload reg
  5162.      dies in this insn, if anyone cares.  */
  5163. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  5164.       if (old != 0
  5165.       && reload_reg_rtx[j] != old
  5166.       && reload_reg_rtx[j] != 0
  5167.       && reload_out[j] == 0
  5168.       && ! reload_inherited[j]
  5169.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j])))
  5170.     {
  5171.       register rtx reloadreg = reload_reg_rtx[j];
  5172.  
  5173. #if 0
  5174.       /* We can't abort here because we need to support this for sched.c.
  5175.          It's not terrible to miss a REG_DEAD note, but we should try
  5176.          to figure out how to do this correctly.  */
  5177.       /* The code below is incorrect for address-only reloads.  */
  5178.       if (reload_when_needed[j] != RELOAD_OTHER
  5179.           && reload_when_needed[j] != RELOAD_FOR_INPUT)
  5180.         abort ();
  5181. #endif
  5182.  
  5183.       /* Add a death note to this insn, for an input reload.  */
  5184.  
  5185.       if ((reload_when_needed[j] == RELOAD_OTHER
  5186.            || reload_when_needed[j] == RELOAD_FOR_INPUT)
  5187.           && ! dead_or_set_p (insn, reloadreg))
  5188.         REG_NOTES (insn)
  5189.           = gen_rtx (EXPR_LIST, REG_DEAD,
  5190.              reloadreg, REG_NOTES (insn));
  5191.     }
  5192.  
  5193.       /* When we inherit a reload, the last marked death of the reload reg
  5194.      may no longer really be a death.  */
  5195.       if (reload_reg_rtx[j] != 0
  5196.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j]))
  5197.       && reload_inherited[j])
  5198.     {
  5199.       /* Handle inheriting an output reload.
  5200.          Remove the death note from the output reload insn.  */
  5201.       if (reload_spill_index[j] >= 0
  5202.           && GET_CODE (reload_in[j]) == REG
  5203.           && spill_reg_store[reload_spill_index[j]] != 0
  5204.           && find_regno_note (spill_reg_store[reload_spill_index[j]],
  5205.                   REG_DEAD, REGNO (reload_reg_rtx[j])))
  5206.         remove_death (REGNO (reload_reg_rtx[j]),
  5207.               spill_reg_store[reload_spill_index[j]]);
  5208.       /* Likewise for input reloads that were inherited.  */
  5209.       else if (reload_spill_index[j] >= 0
  5210.            && GET_CODE (reload_in[j]) == REG
  5211.            && spill_reg_store[reload_spill_index[j]] == 0
  5212.            && reload_inheritance_insn[j] != 0
  5213.            && find_regno_note (reload_inheritance_insn[j], REG_DEAD,
  5214.                        REGNO (reload_reg_rtx[j])))
  5215.         remove_death (REGNO (reload_reg_rtx[j]),
  5216.               reload_inheritance_insn[j]);
  5217.       else
  5218.         {
  5219.           rtx prev;
  5220.  
  5221.           /* We got this register from find_equiv_reg.
  5222.          Search back for its last death note and get rid of it.
  5223.          But don't search back too far.
  5224.          Don't go past a place where this reg is set,
  5225.          since a death note before that remains valid.  */
  5226.           for (prev = PREV_INSN (insn);
  5227.            prev && GET_CODE (prev) != CODE_LABEL;
  5228.            prev = PREV_INSN (prev))
  5229.         if (GET_RTX_CLASS (GET_CODE (prev)) == 'i'
  5230.             && dead_or_set_p (prev, reload_reg_rtx[j]))
  5231.           {
  5232.             if (find_regno_note (prev, REG_DEAD,
  5233.                      REGNO (reload_reg_rtx[j])))
  5234.               remove_death (REGNO (reload_reg_rtx[j]), prev);
  5235.             break;
  5236.           }
  5237.         }
  5238.     }
  5239.  
  5240.       /* We might have used find_equiv_reg above to choose an alternate
  5241.      place from which to reload.  If so, and it died, we need to remove
  5242.      that death and move it to one of the insns we just made.  */
  5243.  
  5244.       if (oldequiv_reg != 0
  5245.       && PRESERVE_DEATH_INFO_REGNO_P (true_regnum (oldequiv_reg)))
  5246.     {
  5247.       rtx prev, prev1;
  5248.  
  5249.       for (prev = PREV_INSN (insn); prev && GET_CODE (prev) != CODE_LABEL;
  5250.            prev = PREV_INSN (prev))
  5251.         if (GET_RTX_CLASS (GET_CODE (prev)) == 'i'
  5252.         && dead_or_set_p (prev, oldequiv_reg))
  5253.           {
  5254.         if (find_regno_note (prev, REG_DEAD, REGNO (oldequiv_reg)))
  5255.           {
  5256.             for (prev1 = this_reload_insn;
  5257.              prev1; prev1 = PREV_INSN (prev1))
  5258.               if (GET_RTX_CLASS (GET_CODE (prev1) == 'i')
  5259.             && reg_overlap_mentioned_for_reload_p (oldequiv_reg,
  5260.                                    PATTERN (prev1)))
  5261.               {
  5262.             REG_NOTES (prev1) = gen_rtx (EXPR_LIST, REG_DEAD,
  5263.                              oldequiv_reg,
  5264.                              REG_NOTES (prev1));
  5265.             break;
  5266.               }
  5267.             remove_death (REGNO (oldequiv_reg), prev);
  5268.           }
  5269.         break;
  5270.           }
  5271.     }
  5272. #endif
  5273.  
  5274.       /* If we are reloading a register that was recently stored in with an
  5275.      output-reload, see if we can prove there was
  5276.      actually no need to store the old value in it.  */
  5277.  
  5278.       if (optimize && reload_inherited[j] && reload_spill_index[j] >= 0
  5279.       /* This is unsafe if some other reload uses the same reg first.  */
  5280.       && (reload_when_needed[j] == RELOAD_OTHER
  5281.           || reload_when_needed[j] == RELOAD_FOR_INPUT
  5282.           || reload_when_needed[j] == RELOAD_FOR_INPUT_RELOAD_ADDRESS)
  5283.       && GET_CODE (reload_in[j]) == REG
  5284. #if 0
  5285.       /* There doesn't seem to be any reason to restrict this to pseudos
  5286.          and doing so loses in the case where we are copying from a
  5287.          register of the wrong class.  */
  5288.       && REGNO (reload_in[j]) >= FIRST_PSEUDO_REGISTER
  5289. #endif
  5290.       && spill_reg_store[reload_spill_index[j]] != 0
  5291.       && dead_or_set_p (insn, reload_in[j])
  5292.       /* This is unsafe if operand occurs more than once in current
  5293.          insn.  Perhaps some occurrences weren't reloaded.  */
  5294.       && count_occurrences (PATTERN (insn), reload_in[j]) == 1)
  5295.     delete_output_reload (insn, j,
  5296.                   spill_reg_store[reload_spill_index[j]]);
  5297.  
  5298.       /* Input-reloading is done.  Now do output-reloading,
  5299.      storing the value from the reload-register after the main insn
  5300.      if reload_out[j] is nonzero.
  5301.  
  5302.      ??? At some point we need to support handling output reloads of
  5303.      JUMP_INSNs or insns that set cc0.  */
  5304.       old = reload_out[j];
  5305.       if (old != 0
  5306.       && reload_reg_rtx[j] != old
  5307.       && reload_reg_rtx[j] != 0)
  5308.     {
  5309.       register rtx reloadreg = reload_reg_rtx[j];
  5310.       register rtx second_reloadreg = 0;
  5311.       rtx prev_insn = PREV_INSN (first_output_reload_insn);
  5312.       rtx note, p;
  5313.       enum machine_mode mode;
  5314.       int special = 0;
  5315.  
  5316.       /* An output operand that dies right away does need a reload,
  5317.          but need not be copied from it.  Show the new location in the
  5318.          REG_UNUSED note.  */
  5319.       if ((GET_CODE (old) == REG || GET_CODE (old) == SCRATCH)
  5320.           && (note = find_reg_note (insn, REG_UNUSED, old)) != 0)
  5321.         {
  5322.           XEXP (note, 0) = reload_reg_rtx[j];
  5323.           continue;
  5324.         }
  5325.       else if (GET_CODE (old) == SCRATCH)
  5326.         /* If we aren't optimizing, there won't be a REG_UNUSED note,
  5327.            but we don't want to make an output reload.  */
  5328.         continue;
  5329.  
  5330. #if 0
  5331.       /* Strip off of OLD any size-increasing SUBREGs such as
  5332.          (SUBREG:SI foo:QI 0).  */
  5333.  
  5334.       while (GET_CODE (old) == SUBREG && SUBREG_WORD (old) == 0
  5335.          && (GET_MODE_SIZE (GET_MODE (old))
  5336.              > GET_MODE_SIZE (GET_MODE (SUBREG_REG (old)))))
  5337.         old = SUBREG_REG (old);
  5338. #endif
  5339.  
  5340.       /* If is a JUMP_INSN, we can't support output reloads yet.  */
  5341.       if (GET_CODE (insn) == JUMP_INSN)
  5342.         abort ();
  5343.  
  5344.       /* Determine the mode to reload in.
  5345.          See comments above (for input reloading).  */
  5346.  
  5347.       mode = GET_MODE (old);
  5348.       if (mode == VOIDmode)
  5349.         abort ();        /* Should never happen for an output.  */
  5350.  
  5351.       /* A strict-low-part output operand needs to be reloaded
  5352.          in the mode of the entire value.  */
  5353.       if (reload_strict_low[j])
  5354.         {
  5355.           mode = GET_MODE (SUBREG_REG (reload_out[j]));
  5356.           /* Encapsulate OLD into that mode.  */
  5357.           /* If OLD is a subreg, then strip it, since the subreg will
  5358.          be altered by this very reload.  */
  5359.           while (GET_CODE (old) == SUBREG && GET_MODE (old) != mode)
  5360.         old = SUBREG_REG (old);
  5361.           if (GET_MODE (old) != VOIDmode
  5362.           && mode != GET_MODE (old))
  5363.         old = gen_rtx (SUBREG, mode, old, 0);
  5364.         }
  5365.  
  5366.       if (GET_MODE (reloadreg) != mode)
  5367.         reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  5368.  
  5369. #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
  5370.  
  5371.       /* If we need two reload regs, set RELOADREG to the intermediate
  5372.          one, since it will be stored into OUT.  We might need a secondary
  5373.          register only for an input reload, so check again here.  */
  5374.  
  5375.       if (reload_secondary_reload[j] >= 0)
  5376.         {
  5377.           rtx real_old = old;
  5378.  
  5379.           if (GET_CODE (old) == REG && REGNO (old) >= FIRST_PSEUDO_REGISTER
  5380.           && reg_equiv_mem[REGNO (old)] != 0)
  5381.         real_old = reg_equiv_mem[REGNO (old)];
  5382.  
  5383.           if((SECONDARY_OUTPUT_RELOAD_CLASS (reload_reg_class[j],
  5384.                          mode, real_old)
  5385.           != NO_REGS))
  5386.         {
  5387.           second_reloadreg = reloadreg;
  5388.           reloadreg = reload_reg_rtx[reload_secondary_reload[j]];
  5389.  
  5390.           /* See if RELOADREG is to be used as a scratch register
  5391.              or as an intermediate register.  */
  5392.           if (reload_secondary_icode[j] != CODE_FOR_nothing)
  5393.             {
  5394.               emit_insn_before ((GEN_FCN (reload_secondary_icode[j])
  5395.                      (real_old, second_reloadreg,
  5396.                       reloadreg)),
  5397.                     first_output_reload_insn);
  5398.               special = 1;
  5399.             }
  5400.           else
  5401.             {
  5402.               /* See if we need both a scratch and intermediate reload
  5403.              register.  */
  5404.               int secondary_reload = reload_secondary_reload[j];
  5405.               enum insn_code tertiary_icode
  5406.             = reload_secondary_icode[secondary_reload];
  5407.               rtx pat;
  5408.  
  5409.               if (GET_MODE (reloadreg) != mode)
  5410.             reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  5411.  
  5412.               if (tertiary_icode != CODE_FOR_nothing)
  5413.             {
  5414.               rtx third_reloadreg
  5415.                 = reload_reg_rtx[reload_secondary_reload[secondary_reload]];
  5416.               pat = (GEN_FCN (tertiary_icode)
  5417.                  (reloadreg, second_reloadreg, third_reloadreg));
  5418.             }
  5419. #ifdef SECONDARY_MEMORY_NEEDED
  5420.               /* If we need a memory location to do the move, do it that way.  */
  5421.               else if (GET_CODE (reloadreg) == REG
  5422.                    && REGNO (reloadreg) < FIRST_PSEUDO_REGISTER
  5423.                    && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (reloadreg)),
  5424.                        REGNO_REG_CLASS (REGNO (second_reloadreg)),
  5425.                        GET_MODE (second_reloadreg)))
  5426.             {
  5427.               /* Get the memory to use and rewrite both registers
  5428.                  to its mode.  */
  5429.               rtx loc = get_secondary_mem (reloadreg,
  5430.                                GET_MODE (second_reloadreg));
  5431.               rtx tmp_reloadreg;
  5432.                 
  5433.               if (GET_MODE (loc) != GET_MODE (second_reloadreg))
  5434.                 second_reloadreg = gen_rtx (REG, GET_MODE (loc),
  5435.                             REGNO (second_reloadreg));
  5436.               
  5437.               if (GET_MODE (loc) != GET_MODE (reloadreg))
  5438.                 tmp_reloadreg = gen_rtx (REG, GET_MODE (loc),
  5439.                              REGNO (reloadreg));
  5440.               else
  5441.                 tmp_reloadreg = reloadreg;
  5442.               
  5443.               emit_insn_before (gen_move_insn (loc, second_reloadreg),
  5444.                         first_output_reload_insn);
  5445.               pat = gen_move_insn (tmp_reloadreg, loc);
  5446.             }
  5447. #endif
  5448.               else
  5449.             pat = gen_move_insn (reloadreg, second_reloadreg);
  5450.  
  5451.               emit_insn_before (pat, first_output_reload_insn);
  5452.             }
  5453.         }
  5454.         }
  5455. #endif
  5456.  
  5457.       /* Output the last reload insn.  */
  5458.       if (! special)
  5459.         {
  5460. #ifdef SECONDARY_MEMORY_NEEDED
  5461.           /* If we need a memory location to do the move, do it that way.  */
  5462.           if (GET_CODE (old) == REG && REGNO (old) < FIRST_PSEUDO_REGISTER
  5463.           && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (old)),
  5464.                           REGNO_REG_CLASS (REGNO (reloadreg)),
  5465.                           GET_MODE (reloadreg)))
  5466.         {
  5467.           /* Get the memory to use and rewrite both registers to
  5468.              its mode.  */
  5469.           rtx loc = get_secondary_mem (old, GET_MODE (reloadreg));
  5470.  
  5471.           if (GET_MODE (loc) != GET_MODE (reloadreg))
  5472.             reloadreg = gen_rtx (REG, GET_MODE (loc),
  5473.                      REGNO (reloadreg));
  5474.  
  5475.           if (GET_MODE (loc) != GET_MODE (old))
  5476.             old = gen_rtx (REG, GET_MODE (loc), REGNO (old));
  5477.  
  5478.           emit_insn_before (gen_move_insn (loc, reloadreg),
  5479.                     first_output_reload_insn);
  5480.           emit_insn_before (gen_move_insn (old, loc),
  5481.                     first_output_reload_insn);
  5482.         }
  5483.           else
  5484. #endif
  5485.         emit_insn_before (gen_move_insn (old, reloadreg),
  5486.                   first_output_reload_insn);
  5487.         }
  5488.  
  5489. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  5490.       /* If final will look at death notes for this reg,
  5491.          put one on the last output-reload insn to use it.  Similarly
  5492.          for any secondary register.  */
  5493.       if (PRESERVE_DEATH_INFO_REGNO_P (REGNO (reloadreg)))
  5494.         for (p = PREV_INSN (first_output_reload_insn);
  5495.          p != prev_insn; p = PREV_INSN (p))
  5496.           if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  5497.           && reg_overlap_mentioned_for_reload_p (reloadreg,
  5498.                              PATTERN (p)))
  5499.         REG_NOTES (p) = gen_rtx (EXPR_LIST, REG_DEAD,
  5500.                      reloadreg, REG_NOTES (p));
  5501.  
  5502. #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
  5503.       if (! special
  5504.           && PRESERVE_DEATH_INFO_REGNO_P (REGNO (second_reloadreg)))
  5505.         for (p = PREV_INSN (first_output_reload_insn);
  5506.          p != prev_insn; p = PREV_INSN (p))
  5507.           if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  5508.           && reg_overlap_mentioned_for_reload_p (second_reloadreg,
  5509.                              PATTERN (p)))
  5510.         REG_NOTES (p) = gen_rtx (EXPR_LIST, REG_DEAD,
  5511.                      second_reloadreg, REG_NOTES (p));
  5512. #endif
  5513. #endif
  5514.       /* Look at all insns we emitted, just to be safe.  */
  5515.       for (p = NEXT_INSN (prev_insn); p != first_output_reload_insn;
  5516.            p = NEXT_INSN (p))
  5517.         if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
  5518.           {
  5519.         /* If this output reload doesn't come from a spill reg,
  5520.            clear any memory of reloaded copies of the pseudo reg.
  5521.            If this output reload comes from a spill reg,
  5522.            reg_has_output_reload will make this do nothing.  */
  5523.         note_stores (PATTERN (p), forget_old_reloads_1);
  5524.  
  5525.         if (reg_mentioned_p (reload_reg_rtx[j], PATTERN (p)))
  5526.           store_insn = p;
  5527.           }
  5528.  
  5529.       first_output_reload_insn = NEXT_INSN (prev_insn);
  5530.     }
  5531.  
  5532.       if (reload_spill_index[j] >= 0)
  5533.     new_spill_reg_store[reload_spill_index[j]] = store_insn;
  5534.     }
  5535.  
  5536.   /* Move death notes from INSN
  5537.      to output-operand-address and output reload insns.  */
  5538. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  5539.   {
  5540.     rtx insn1;
  5541.     /* Loop over those insns, last ones first.  */
  5542.     for (insn1 = PREV_INSN (following_insn); insn1 != insn;
  5543.      insn1 = PREV_INSN (insn1))
  5544.       if (GET_CODE (insn1) == INSN && GET_CODE (PATTERN (insn1)) == SET)
  5545.     {
  5546.       rtx source = SET_SRC (PATTERN (insn1));
  5547.       rtx dest = SET_DEST (PATTERN (insn1));
  5548.  
  5549.       /* The note we will examine next.  */
  5550.       rtx reg_notes = REG_NOTES (insn);
  5551.       /* The place that pointed to this note.  */
  5552.       rtx *prev_reg_note = ®_NOTES (insn);
  5553.  
  5554.       /* If the note is for something used in the source of this
  5555.          reload insn, or in the output address, move the note.  */
  5556.       while (reg_notes)
  5557.         {
  5558.           rtx next_reg_notes = XEXP (reg_notes, 1);
  5559.           if (REG_NOTE_KIND (reg_notes) == REG_DEAD
  5560.           && GET_CODE (XEXP (reg_notes, 0)) == REG
  5561.           && ((GET_CODE (dest) != REG
  5562.                && reg_overlap_mentioned_for_reload_p (XEXP (reg_notes, 0),
  5563.                                   dest))
  5564.               || reg_overlap_mentioned_for_reload_p (XEXP (reg_notes, 0),
  5565.                                  source)))
  5566.         {
  5567.           *prev_reg_note = next_reg_notes;
  5568.           XEXP (reg_notes, 1) = REG_NOTES (insn1);
  5569.           REG_NOTES (insn1) = reg_notes;
  5570.         }
  5571.           else
  5572.         prev_reg_note = &XEXP (reg_notes, 1);
  5573.  
  5574.           reg_notes = next_reg_notes;
  5575.         }
  5576.     }
  5577.   }
  5578. #endif
  5579.  
  5580.   /* For all the spill regs newly reloaded in this instruction,
  5581.      record what they were reloaded from, so subsequent instructions
  5582.      can inherit the reloads.
  5583.  
  5584.      Update spill_reg_store for the reloads of this insn.
  5585.      Copy the elements that were updated in the loop above.  */
  5586.  
  5587.   for (j = 0; j < n_reloads; j++)
  5588.     {
  5589.       register int r = reload_order[j];
  5590.       register int i = reload_spill_index[r];
  5591.  
  5592.       /* I is nonneg if this reload used one of the spill regs.
  5593.      If reload_reg_rtx[r] is 0, this is an optional reload
  5594.      that we opted to ignore.  */
  5595.  
  5596.       if (i >= 0 && reload_reg_rtx[r] != 0)
  5597.     {
  5598.       /* First, clear out memory of what used to be in this spill reg.
  5599.          If consecutive registers are used, clear them all.  */
  5600.       int nr
  5601.         = HARD_REGNO_NREGS (spill_regs[i], GET_MODE (reload_reg_rtx[r]));
  5602.       int k;
  5603.  
  5604.       for (k = 0; k < nr; k++)
  5605.         {
  5606.           reg_reloaded_contents[spill_reg_order[spill_regs[i] + k]] = -1;
  5607.           reg_reloaded_insn[spill_reg_order[spill_regs[i] + k]] = 0;
  5608.         }
  5609.  
  5610.       /* Maybe the spill reg contains a copy of reload_out.  */
  5611.       if (reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  5612.         {
  5613.           register int nregno = REGNO (reload_out[r]);
  5614.  
  5615.           spill_reg_store[i] = new_spill_reg_store[i];
  5616.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  5617.  
  5618.           for (k = 0; k < nr; k++)
  5619.         {
  5620.           reg_reloaded_contents[spill_reg_order[spill_regs[i] + k]]
  5621.             = nregno;
  5622.           reg_reloaded_insn[spill_reg_order[spill_regs[i] + k]] = insn;
  5623.         }
  5624.         }
  5625.  
  5626.       /* Maybe the spill reg contains a copy of reload_in.  */
  5627.       else if (reload_out[r] == 0
  5628.            && reload_in[r] != 0
  5629.            && (GET_CODE (reload_in[r]) == REG
  5630.                || GET_CODE (reload_in_reg[r]) == REG))
  5631.         {
  5632.           register int nregno;
  5633.           if (GET_CODE (reload_in[r]) == REG)
  5634.         nregno = REGNO (reload_in[r]);
  5635.           else
  5636.         nregno = REGNO (reload_in_reg[r]);
  5637.  
  5638.           /* If there are two separate reloads (one in and one out)
  5639.          for the same (hard or pseudo) reg,
  5640.          leave reg_last_reload_reg set
  5641.          based on the output reload.
  5642.          Otherwise, set it from this input reload.  */
  5643.           if (!reg_has_output_reload[nregno]
  5644.           /* But don't do so if another input reload
  5645.              will clobber this one's value.  */
  5646.           && reload_reg_reaches_end_p (spill_regs[i],
  5647.                            reload_when_needed[r]))
  5648.         {
  5649.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  5650.  
  5651.           /* Unless we inherited this reload, show we haven't
  5652.              recently done a store.  */
  5653.           if (! reload_inherited[r])
  5654.             spill_reg_store[i] = 0;
  5655.  
  5656.           for (k = 0; k < nr; k++)
  5657.             {
  5658.               reg_reloaded_contents[spill_reg_order[spill_regs[i] + k]]
  5659.             = nregno;
  5660.               reg_reloaded_insn[spill_reg_order[spill_regs[i] + k]]
  5661.             = insn;
  5662.             }
  5663.         }
  5664.         }
  5665.     }
  5666.  
  5667.       /* The following if-statement was #if 0'd in 1.34 (or before...).
  5668.      It's reenabled in 1.35 because supposedly nothing else
  5669.      deals with this problem.  */
  5670.  
  5671.       /* If a register gets output-reloaded from a non-spill register,
  5672.      that invalidates any previous reloaded copy of it.
  5673.      But forget_old_reloads_1 won't get to see it, because
  5674.      it thinks only about the original insn.  So invalidate it here.  */
  5675.       if (i < 0 && reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  5676.     {
  5677.       register int nregno = REGNO (reload_out[r]);
  5678.       reg_last_reload_reg[nregno] = 0;
  5679.     }
  5680.     }
  5681. }
  5682.  
  5683. /* Emit code before BEFORE_INSN to perform an input reload of IN to RELOADREG.
  5684.    Returns first insn emitted.  */
  5685.  
  5686. rtx
  5687. gen_input_reload (reloadreg, in, before_insn)
  5688.      rtx reloadreg;
  5689.      rtx in;
  5690.      rtx before_insn;
  5691. {
  5692.   register rtx prev_insn = PREV_INSN (before_insn);
  5693.  
  5694.   /* How to do this reload can get quite tricky.  Normally, we!are being
  5695.      asked to reload a simple operand, such as a MEM, a constant, or a pseudo
  5696.      register that didn't get a hard register.  In that case we can just
  5697.      call emit_move_insn.
  5698.  
  5699.      We can also be asked to reload a PLUS that adds either two registers or
  5700.      a register and a constant or MEM.  This can occur during frame pointer
  5701.      elimination.  That case if handled by trying to emit a single insn
  5702.      to perform the add.  If it is not valid, we use a two insn sequence.
  5703.  
  5704.      Finally, we could be called to handle an 'o' constraint by putting
  5705.      an address into a register.  In that case, we first try to do this
  5706.      with a named pattern of "reload_load_address".  If no such pattern
  5707.      exists, we just emit a SET insn and hope for the best (it will normally
  5708.      be valid on machines that use 'o').
  5709.  
  5710.      This entire process is made complex because reload will never
  5711.      process the insns we generate here and so we must ensure that
  5712.      they will fit their constraints and also by the fact that parts of
  5713.      IN might be being reloaded separately and replaced with spill registers.
  5714.      Because of this, we are, in some sense, just guessing the right approach
  5715.      here.  The one listed above seems to work.
  5716.  
  5717.      ??? At some point, this whole thing needs to be rethought.  */
  5718.  
  5719. #ifdef MPW
  5720.   MPW_reload_again = MPW_reload_again || GET_MODE(reloadreg) == XFmode 
  5721.           /*|| GET_MODE(reloadreg) == DFmode*/;
  5722. #endif
  5723.   if (GET_CODE (in) == PLUS
  5724.       && GET_CODE (XEXP (in, 0)) == REG
  5725.       && (GET_CODE (XEXP (in, 1)) == REG
  5726.       || CONSTANT_P (XEXP (in, 1))
  5727.       || GET_CODE (XEXP (in, 1)) == MEM))
  5728.     {
  5729.       /* We need to compute the sum of what is either a register and a
  5730.      constant, a register and memory, or a hard register and a pseudo
  5731.      register and put it into the reload register.  The best possible way
  5732.      of doing this is if the machine has a three-operand ADD insn that
  5733.      accepts the required operands.
  5734.  
  5735.      The simplest approach is to try to generate such an insn and see if it
  5736.      is recognized and matches its constraints.  If so, it can be used.
  5737.  
  5738.      It might be better not to actually emit the insn unless it is valid,
  5739.      but we need to pass the insn as an operand to `recog' and
  5740.      `insn_extract' and it is simpler to emit and then delete the insn if
  5741.      not valid than to dummy things up.  */
  5742.  
  5743.       rtx op0, op1, tem, insn;
  5744.       int code;
  5745.  
  5746.       op0 = find_replacement (&XEXP (in, 0));
  5747.       op1 = find_replacement (&XEXP (in, 1));
  5748.  
  5749.       /* Since constraint checking is strict, commutativity won't be
  5750.      checked, so we need to do that here to avoid spurious failure
  5751.      if the add instruction is two-address and the second operand
  5752.      of the add is the same as the reload reg, which is frequently
  5753.      the case.  If the insn would be A = B + A, rearrange it so
  5754.      it will be A = A + B as constrain_operands expects. */
  5755.  
  5756.       if (GET_CODE (XEXP (in, 1)) == REG
  5757.       && REGNO (reloadreg) == REGNO (XEXP (in, 1)))
  5758.     tem = op0, op0 = op1, op1 = tem;
  5759.  
  5760.       if (op0 != XEXP (in, 0) || op1 != XEXP (in, 1))
  5761.     in = gen_rtx (PLUS, GET_MODE (in), op0, op1);
  5762.  
  5763.       insn = emit_insn_before (gen_rtx (SET, VOIDmode, reloadreg, in),
  5764.                    before_insn);
  5765.       code = recog_memoized (insn);
  5766.  
  5767.       if (code >= 0)
  5768.     {
  5769.       insn_extract (insn);
  5770.       /* We want constrain operands to treat this insn strictly in
  5771.          its validity determination, i.e., the way it would after reload
  5772.          has completed.  */
  5773.       if (constrain_operands (code, 1))
  5774.         return insn;
  5775.     }
  5776.  
  5777.       if (PREV_INSN (insn))
  5778.     NEXT_INSN (PREV_INSN (insn)) = NEXT_INSN (insn);
  5779.       if (NEXT_INSN (insn))
  5780.     PREV_INSN (NEXT_INSN (insn)) = PREV_INSN (insn);
  5781.  
  5782.       /* If that failed, we must use a conservative two-insn sequence.
  5783.      use move to copy constant, MEM, or pseudo register to the reload
  5784.      register since "move" will be able to handle an arbitrary operand,
  5785.      unlike add which can't, in general.  Then add the registers.
  5786.  
  5787.      If there is another way to do this for a specific machine, a
  5788.      DEFINE_PEEPHOLE should be specified that recognizes the sequence
  5789.      we emit below.  */
  5790.  
  5791.       if (CONSTANT_P (op1) || GET_CODE (op1) == MEM
  5792.       || (GET_CODE (op1) == REG
  5793.           && REGNO (op1) >= FIRST_PSEUDO_REGISTER))
  5794.     tem = op0, op0 = op1, op1 = tem;
  5795.  
  5796.       emit_insn_before (gen_move_insn (reloadreg, op0), before_insn);
  5797.  
  5798.       /* If OP0 and OP1 are the same, we can use RELOADREG for OP1.
  5799.      This fixes a problem on the 32K where the stack pointer cannot
  5800.      be used as an operand of an add insn.  */
  5801.  
  5802.       if (rtx_equal_p (op0, op1))
  5803.     op1 = reloadreg;
  5804.  
  5805.       emit_insn_before (gen_add2_insn (reloadreg, op1), before_insn);
  5806.     }
  5807.  
  5808. #ifdef SECONDARY_MEMORY_NEEDED
  5809.   /* If we need a memory location to do the move, do it that way.  */
  5810.   else if (GET_CODE (in) == REG && REGNO (in) < FIRST_PSEUDO_REGISTER
  5811.        && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (in)),
  5812.                        REGNO_REG_CLASS (REGNO (reloadreg)),
  5813.                        GET_MODE (reloadreg)))
  5814.     {
  5815.       /* Get the memory to use and rewrite both registers to its mode.  */
  5816.       rtx loc = get_secondary_mem (in, GET_MODE (reloadreg));
  5817.  
  5818.       if (GET_MODE (loc) != GET_MODE (reloadreg))
  5819.     reloadreg = gen_rtx (REG, GET_MODE (loc), REGNO (reloadreg));
  5820.  
  5821.       if (GET_MODE (loc) != GET_MODE (in))
  5822.     in = gen_rtx (REG, GET_MODE (loc), REGNO (in));
  5823.  
  5824.       emit_insn_before (gen_move_insn (loc, in), before_insn);
  5825.       emit_insn_before (gen_move_insn (reloadreg, loc), before_insn);
  5826.     }
  5827. #endif
  5828.  
  5829.   /* If IN is a simple operand, use gen_move_insn.  */
  5830.   else if (GET_RTX_CLASS (GET_CODE (in)) == 'o' || GET_CODE (in) == SUBREG)
  5831.     emit_insn_before (gen_move_insn (reloadreg, in), before_insn);
  5832.  
  5833. #ifdef HAVE_reload_load_address
  5834.   else if (HAVE_reload_load_address)
  5835.     emit_insn_before (gen_reload_load_address (reloadreg, in), before_insn);
  5836. #endif
  5837.  
  5838.   /* Otherwise, just write (set REGLOADREG IN) and hope for the best.  */
  5839.   else
  5840.     emit_insn_before (gen_rtx (SET, VOIDmode, reloadreg, in), before_insn);
  5841.  
  5842.   /* Return the first insn emitted.
  5843.      We can not just return PREV_INSN (before_insn), because there may have
  5844.      been multiple instructions emitted.  Also note that gen_move_insn may
  5845.      emit more than one insn itself, so we can not assume that there is one
  5846.      insn emitted per emit_insn_before call.  */
  5847.  
  5848. #if 0/*def MPW*/
  5849. {
  5850.   int code = recog_memoized (NEXT_INSN (prev_insn));
  5851.   if (code >= 0)
  5852.   {
  5853.     insn_extract (NEXT_INSN (prev_insn));
  5854.     /* We want constrain operands to treat this insn strictly in
  5855.        its validity determination, i.e., the way it would after reload
  5856.        has completed.  */
  5857.     if (!constrain_operands (code, 0)) {
  5858.       debug_rtx(NEXT_INSN (prev_insn));
  5859.       MPW_reload_again = 1;
  5860.     }
  5861.   }
  5862. }
  5863. #endif
  5864.   return NEXT_INSN (prev_insn);
  5865. }
  5866.  
  5867. /* Delete a previously made output-reload
  5868.    whose result we now believe is not needed.
  5869.    First we double-check.
  5870.  
  5871.    INSN is the insn now being processed.
  5872.    OUTPUT_RELOAD_INSN is the insn of the output reload.
  5873.    J is the reload-number for this insn.  */
  5874.  
  5875. /*static.c*/ void
  5876. delete_output_reload (insn, j, output_reload_insn)
  5877.      rtx insn;
  5878.      int j;
  5879.      rtx output_reload_insn;
  5880. {
  5881.   register rtx i1;
  5882.  
  5883.   /* Get the raw pseudo-register referred to.  */
  5884.  
  5885.   rtx reg = reload_in[j];
  5886.   while (GET_CODE (reg) == SUBREG)
  5887.     reg = SUBREG_REG (reg);
  5888.  
  5889.   /* If the pseudo-reg we are reloading is no longer referenced
  5890.      anywhere between the store into it and here,
  5891.      and no jumps or labels intervene, then the value can get
  5892.      here through the reload reg alone.
  5893.      Otherwise, give up--return.  */
  5894.   for (i1 = NEXT_INSN (output_reload_insn);
  5895.        i1 != insn; i1 = NEXT_INSN (i1))
  5896.     {
  5897.       if (GET_CODE (i1) == CODE_LABEL || GET_CODE (i1) == JUMP_INSN)
  5898.     return;
  5899.       if ((GET_CODE (i1) == INSN || GET_CODE (i1) == CALL_INSN)
  5900.       && reg_mentioned_p (reg, PATTERN (i1)))
  5901.     return;
  5902.     }
  5903.  
  5904.   /* If this insn will store in the pseudo again,
  5905.      the previous store can be removed.  */
  5906.   if (reload_out[j] == reload_in[j])
  5907.     delete_insn (output_reload_insn);
  5908.  
  5909.   /* See if the pseudo reg has been completely replaced
  5910.      with reload regs.  If so, delete the store insn
  5911.      and forget we had a stack slot for the pseudo.  */
  5912.   else if (reg_n_deaths[REGNO (reg)] == 1
  5913.        && reg_basic_block[REGNO (reg)] >= 0
  5914.        && find_regno_note (insn, REG_DEAD, REGNO (reg)))
  5915.     {
  5916.       rtx i2;
  5917.  
  5918.       /* We know that it was used only between here
  5919.      and the beginning of the current basic block.
  5920.      (We also know that the last use before INSN was
  5921.      the output reload we are thinking of deleting, but never mind that.)
  5922.      Search that range; see if any ref remains.  */
  5923.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  5924.     {
  5925.       rtx set = single_set (i2);
  5926.  
  5927.       /* Uses which just store in the pseudo don't count,
  5928.          since if they are the only uses, they are dead.  */
  5929.       if (set != 0 && SET_DEST (set) == reg)
  5930.         continue;
  5931.       if (GET_CODE (i2) == CODE_LABEL
  5932.           || GET_CODE (i2) == JUMP_INSN)
  5933.         break;
  5934.       if ((GET_CODE (i2) == INSN || GET_CODE (i2) == CALL_INSN)
  5935.           && reg_mentioned_p (reg, PATTERN (i2)))
  5936.         /* Some other ref remains;
  5937.            we can't do anything.  */
  5938.         return;
  5939.     }
  5940.  
  5941.       /* Delete the now-dead stores into this pseudo.  */
  5942.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  5943.     {
  5944.       rtx set = single_set (i2);
  5945.  
  5946.       if (set != 0 && SET_DEST (set) == reg)
  5947.         delete_insn (i2);
  5948.       if (GET_CODE (i2) == CODE_LABEL
  5949.           || GET_CODE (i2) == JUMP_INSN)
  5950.         break;
  5951.     }
  5952.  
  5953.       /* For the debugging info,
  5954.      say the pseudo lives in this reload reg.  */
  5955.       reg_renumber[REGNO (reg)] = REGNO (reload_reg_rtx[j]);
  5956.       alter_reg (REGNO (reg), -1);
  5957.     }
  5958. }
  5959.  
  5960.  
  5961. /* Output reload-insns to reload VALUE into RELOADREG.
  5962.    VALUE is an autoincrement or autodecrement RTX whose operand
  5963.    is a register or memory location;
  5964.    so reloading involves incrementing that location.
  5965.  
  5966.    INC_AMOUNT is the number to increment or decrement by (always positive).
  5967.    This cannot be deduced from VALUE.
  5968.  
  5969.    INSN is the insn before which the new insns should be emitted.
  5970.  
  5971.    The return value is the first of the insns emitted.  */
  5972.  
  5973. static rtx
  5974. inc_for_reload (reloadreg, value, inc_amount, insn)
  5975.      rtx reloadreg;
  5976.      rtx value;
  5977.      int inc_amount;
  5978.      rtx insn;
  5979. {
  5980.   /* REG or MEM to be copied and incremented.  */
  5981.   rtx incloc = XEXP (value, 0);
  5982.   /* Nonzero if increment after copying.  */
  5983.   int post = (GET_CODE (value) == POST_DEC || GET_CODE (value) == POST_INC);
  5984.   rtx prev = PREV_INSN (insn);
  5985.   rtx inc;
  5986.   rtx add_insn;
  5987.   int code;
  5988.  
  5989.   /* No hard register is equivalent to this register after
  5990.      inc/dec operation.  If REG_LAST_RELOAD_REG were non-zero,
  5991.      we could inc/dec that register as well (maybe even using it for
  5992.      the source), but I'm not sure it's worth worrying about.  */
  5993.   if (GET_CODE (incloc) == REG)
  5994.     reg_last_reload_reg[REGNO (incloc)] = 0;
  5995.  
  5996.   if (GET_CODE (value) == PRE_DEC || GET_CODE (value) == POST_DEC)
  5997.     inc_amount = - inc_amount;
  5998.  
  5999.   inc = GEN_INT (inc_amount);
  6000.  
  6001.   /* If this is post-increment, first copy the location to the reload reg.  */
  6002.   if (post)
  6003.     emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  6004.  
  6005.   /* See if we can directly increment INCLOC.  Use a method similar to that
  6006.      in gen_input_reload.  */
  6007.  
  6008.   add_insn = emit_insn_before (gen_rtx (SET, VOIDmode, incloc,
  6009.                     gen_rtx (PLUS, GET_MODE (incloc),
  6010.                          incloc, inc)), insn);
  6011.                               
  6012.   code = recog_memoized (add_insn);
  6013.   if (code >= 0)
  6014.     {
  6015.       insn_extract (add_insn);
  6016.       if (constrain_operands (code, 1))
  6017.     {
  6018.       /* If this is a pre-increment and we have incremented the value
  6019.          where it lives, copy the incremented value to RELOADREG to
  6020.          be used as an address.  */
  6021.  
  6022.       if (! post)
  6023.         emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  6024.       return NEXT_INSN (prev);
  6025.     }
  6026.     }
  6027.  
  6028.   if (PREV_INSN (add_insn))
  6029.     NEXT_INSN (PREV_INSN (add_insn)) = NEXT_INSN (add_insn);
  6030.   if (NEXT_INSN (add_insn))
  6031.     PREV_INSN (NEXT_INSN (add_insn)) = PREV_INSN (add_insn);
  6032.  
  6033.   /* If couldn't do the increment directly, must increment in RELOADREG.
  6034.      The way we do this depends on whether this is pre- or post-increment.
  6035.      For pre-increment, copy INCLOC to the reload register, increment it
  6036.      there, then save back.  */
  6037.  
  6038.   if (! post)
  6039.     {
  6040.       emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  6041.       emit_insn_before (gen_add2_insn (reloadreg, inc), insn);
  6042.       emit_insn_before (gen_move_insn (incloc, reloadreg), insn);
  6043.     }
  6044.   else
  6045.     {
  6046.       /* Postincrement.
  6047.      Because this might be a jump insn or a compare, and because RELOADREG
  6048.      may not be available after the insn in an input reload, we must do
  6049.      the incrementation before the insn being reloaded for.
  6050.  
  6051.      We have already copied INCLOC to RELOADREG.  Increment the copy in
  6052.      RELOADREG, save that back, then decrement RELOADREG so it has
  6053.      the original value.  */
  6054.  
  6055.       emit_insn_before (gen_add2_insn (reloadreg, inc), insn);
  6056.       emit_insn_before (gen_move_insn (incloc, reloadreg), insn);
  6057.       emit_insn_before (gen_add2_insn (reloadreg, GEN_INT (-inc_amount)),
  6058.             insn);
  6059.     }
  6060.  
  6061.   return NEXT_INSN (prev);
  6062. }
  6063.  
  6064. /* Return 1 if we are certain that the constraint-string STRING allows
  6065.    the hard register REG.  Return 0 if we can't be sure of this.  */
  6066.  
  6067. static int
  6068. constraint_accepts_reg_p (string, reg)
  6069.      char *string;
  6070.      rtx reg;
  6071. {
  6072.   int value = 0;
  6073.   int regno = true_regnum (reg);
  6074.   int c;
  6075.  
  6076.   /* Initialize for first alternative.  */
  6077.   value = 0;
  6078.   /* Check that each alternative contains `g' or `r'.  */
  6079.   while (1)
  6080.     switch (c = *string++)
  6081.       {
  6082.       case 0:
  6083.     /* If an alternative lacks `g' or `r', we lose.  */
  6084.     return value;
  6085.       case ',':
  6086.     /* If an alternative lacks `g' or `r', we lose.  */
  6087.     if (value == 0)
  6088.       return 0;
  6089.     /* Initialize for next alternative.  */
  6090.     value = 0;
  6091.     break;
  6092.       case 'g':
  6093.       case 'r':
  6094.     /* Any general reg wins for this alternative.  */
  6095.     if (TEST_HARD_REG_BIT (reg_class_contents[(int) GENERAL_REGS], regno))
  6096.       value = 1;
  6097.     break;
  6098.       default:
  6099.     /* Any reg in specified class wins for this alternative.  */
  6100.     {
  6101.       enum reg_class class = REG_CLASS_FROM_LETTER (c);
  6102.  
  6103.       if (TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno))
  6104.         value = 1;
  6105.     }
  6106.       }
  6107. }
  6108.  
  6109. /* Return the number of places FIND appears within X, but don't count
  6110.    an occurrence if some SET_DEST is FIND.  */
  6111.  
  6112. static int
  6113. count_occurrences (x, find)
  6114.      register rtx x, find;
  6115. {
  6116.   register int i, j;
  6117.   register enum rtx_code code;
  6118.   register char *format_ptr;
  6119.   int count;
  6120.  
  6121.   if (x == find)
  6122.     return 1;
  6123.   if (x == 0)
  6124.     return 0;
  6125.  
  6126.   code = GET_CODE (x);
  6127.  
  6128.   switch (code)
  6129.     {
  6130.     case REG:
  6131.     case QUEUED:
  6132.     case CONST_INT:
  6133.     case CONST_DOUBLE:
  6134.     case SYMBOL_REF:
  6135.     case CODE_LABEL:
  6136.     case PC:
  6137.     case CC0:
  6138.       return 0;
  6139.  
  6140.     case SET:
  6141.       if (SET_DEST (x) == find)
  6142.     return count_occurrences (SET_SRC (x), find);
  6143.       break;
  6144.     }
  6145.  
  6146.   format_ptr = GET_RTX_FORMAT (code);
  6147.   count = 0;
  6148.  
  6149.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  6150.     {
  6151.       switch (*format_ptr++)
  6152.     {
  6153.     case 'e':
  6154.       count += count_occurrences (XEXP (x, i), find);
  6155.       break;
  6156.  
  6157.     case 'E':
  6158.       if (XVEC (x, i) != NULL)
  6159.         {
  6160.           for (j = 0; j < XVECLEN (x, i); j++)
  6161.         count += count_occurrences (XVECEXP (x, i, j), find);
  6162.         }
  6163.       break;
  6164.     }
  6165.     }
  6166.   return count;
  6167. }
  6168.